473,395 Members | 1,742 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

where are these macros defined? can I use it a release ver code?

Nov 14 '05 #1
5 2679
What exactly is your question? You can use __FILE__ and __LINE__ in
both DEBUG and NON_DEBUG versions. Or was it something else that you
wanted to ask?

--
Imanpreet Singh Arora

Nov 14 '05 #2
ba*********@gmail.com writes:
where are these macros defined? can I use it a release ver code?


Please include your complete question in the body of your article; not
all newsreaders show the subject in a useful manner.

The question was:

can I use __FILE__ ,__LINE__ etc. in a code witout DEBUG defined?

And the answer is yes. __FILE__ and __LINE__ (along with several
others) are predefined macros, unconditionally defined by the
preprocessor.

There's nothing called "DEBUG" in standard C (though you can define
something by that name for yourself). (You might be thinking of
NDEBUG, a macro that can be defined to cause the assert() macro to
become a no-op.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #3
A good practise is not to use __FILE__ in production code, as compiler
converts __FILE__ into const strings, which takes up static memory.

Nov 14 '05 #4
In article <11**********************@l41g2000cwc.googlegroups .com>,
leon <le********@yahoo.com> wrote:
:A good practise is not to use __FILE__ in production code, as compiler
:converts __FILE__ into const strings, which takes up static memory.

??

Static memory is going to take no more space than dynamic memory, since
malloc() returns a pointer that is worst-case aligned (but you could
calloc() for a less-aligned result.)

malloc() and friends are going to have the overhead of keeping track of
the size and location of the allocated chunk, which is going to take
more space than just storing the string.

The code to compute __FILE__ on the fly is surely going to take more
space than the constant string; I'm not sure how you would even write
such code except by mousing into the debugging symbols for the
executable, which would be pretty non-portable and would very likely
take more space than the constant string would.

The only thing I can see is that if the string were dynamic then you
could reclaim the space once you have determined you do not need it...
but figuring out for sure that you will no longer even indirectly or
through a function pointer call anything from a particular file is
going to require non-trivial embedded logic that would surely be messy
and take more space than was saved.

Perhaps you could expand on your point?
--
"No one has the right to destroy another person's belief by
demanding empirical evidence." -- Ann Landers
Nov 14 '05 #5
"leon" <le********@yahoo.com> writes:
A good practise is not to use __FILE__ in production code, as compiler
converts __FILE__ into const strings, which takes up static memory.


Of course it's going to take up memory. That's what memory is for.

If you need the value of __FILE__, use it. There's probably no way to
get the same information that's going to consume less memory.

Whether you want to use it in production code depends entirely on how
you want production code to behave. __FILE__ and __LINE__ are
typically used in error messages like "Something bad happened on line
42 of foobar.c". If you don't want your production code producing
messages like that, don't use __FILE__ and __LINE__ (you can use #if
or #ifdef to eliminate the code that uses it) -- but keep in mind that
there's a risk in building production and non-production code
differently.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Spry | last post by:
Hi, I wanted to write macros for finding the number of memory allocations and deallocations also wanted to find the locations. The code I have is a pretty big one. I have a wrapper on top of...
9
by: qazmlp | last post by:
How exactly __FILE__ and __LINE__ macros are defined? Or, Is the definition of these macros implementation dependent ? I am wondering how easily they can get the file name and line number...
5
by: jake1138 | last post by:
I couldn't find an example of this anywhere so I post it in the hope that someone finds it useful. I believe this is compiler specific (I'm using gcc), as C99 defines __VA_ARGS__. Comments are...
3
by: wsq | last post by:
in C++ we can use __FILE__ and __LINE__ to help us locating the bug, is there anything like these in C# ? thanks, wsq
7
by: Kenneth Brody | last post by:
Am I correct that using __FILE__ and __LINE__ within a macro will expand to the filename and line in which the macro is invoked, rather than where it is defined? For example, in a header file: ...
19
by: v4vijayakumar | last post by:
why the following statement dumps the core(Segmentation fault)? printf("%s\n", __FILE__);
5
by: Neo | last post by:
Hie, Can I put __FILE__ and __LINE__ macros inside the class function which may not be inline. And void function() { classobject::LogInfo(...); } Internally LogInfo should log file name...
9
by: Neo | last post by:
Hi Friends, I am planning to use "__FILE__,__LINE__,__FUNCTION__ " for a logging component in my class. In debug build I gets all information. I tried with release mode also and it works. But I...
4
by: allan.mcrae | last post by:
As part of a very simple memory leak detector, I am trying to store the value of __FILE__ in a char*. Since gcc4.2 I get the following warning... warning: deprecated conversion from string...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.