473,804 Members | 3,194 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2706
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*********@gma il.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_Keit h) 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************ **********@l41g 2000cwc.googleg roups.com>,
leon <le********@yah oo.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********@yah oo.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_Keit h) 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
6949
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 malloc(int x) as Xmalloc(int x) Now I want to write a macro for Xmalloc which can log the location of the file and the line and the number of bytes allocated.
9
25264
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 respectively.
5
12096
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 welcome. This will print the file name and line number followed by a format string and a variable number of arguments. The key here is that you MUST have a space between __LINE__ and the last comma, otherwise __LINE__ gets eaten by the ## if...
3
2019
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
2682
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: #ifdef DEBUG #define LOGIT(note) DoLogging(__FILE__,__LINE__,note) #else #define LOGIT(note)
19
5470
by: v4vijayakumar | last post by:
why the following statement dumps the core(Segmentation fault)? printf("%s\n", __FILE__);
5
3370
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 and line number. Here I dont
9
9434
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 want to verify that will I able to get this information at any kind of build with all possible optimizations? Regards Vikram S
4
3896
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 constant to 'char*' object. The macro of delete assigns this to a global char* which is used to track where deletions were made. Something like: #define delete delete_FILE_ = __FILE__, \
0
9706
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10332
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10321
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10077
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6853
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5522
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4300
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3820
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2991
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.