-
February 18th, 2011, 11:20 PM
#1
how to disable __FILE__ ?
I have this C++ library that uses __LINE__ and _FILE__ preprocessor directives all over the place,
and I would like to disable it or turn it off without having to explicitly remove them myself.
They insert source code directories into my compiled files, making them much larger than they have to be.
Even in release mode, they're in there.
-
February 19th, 2011, 01:57 AM
#2
Re: how to disable __FILE__ ?
Are you sure that this is really a problem? /GF compiler option allows to have only one copy of every string in executable file. So, total number of strings added to executable by this library is equal to number of source files in the library.
__FILE__ and __LINE__ macros are very useful for error handling and diagnostics. It is a good idea to learn from library writers, how to use this feature, instead of removing it.
http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
-
February 19th, 2011, 03:23 AM
#3
Re: how to disable __FILE__ ?
Originally Posted by Alex F
Are you sure that this is really a problem? /GF compiler option allows to have only one copy of every string in executable file. So, total number of strings added to executable by this library is equal to number of source files in the library.
__FILE__ and __LINE__ macros are very useful for error handling and diagnostics. It is a good idea to learn from library writers, how to use this feature, instead of removing it.
http://msdn.microsoft.com/en-us/libr...=vs.80%29.aspx
Thanks, I understand their purpose, but that doesn't diminish the fact I want them removed from my release build.
I take it from your response, there's no way to turn them off.
-
February 19th, 2011, 04:36 AM
#4
Re: how to disable __FILE__ ?
That's strange.
I just wrote a small test and __FILE__ resolves to a full path in debug builds but just to the filename in release builds.
Which version of VC++ are you using?
-
February 19th, 2011, 05:34 PM
#5
Re: how to disable __FILE__ ?
Originally Posted by Marc G
That's strange.
I just wrote a small test and __FILE__ resolves to a full path in debug builds but just to the filename in release builds.
Which version of VC++ are you using?
MSVC++ 2008. I can see the full filepaths in my hex editor. I'm compiling a dynamic library (.dll) if that matters.
I thought I just ask to see if there's an easy way to get rid of them, before I start digging into the source code
and remove them by hand.
Typically, I see most people use a #define switch and set them to empty values, but in some cases, I guess they're being lazy and
forget about it.
Last edited by sinclaire; February 19th, 2011 at 06:11 PM.
-
February 20th, 2011, 03:30 AM
#6
Re: how to disable __FILE__ ?
Originally Posted by sinclaire
Typically, I see most people use a #define switch and set them to empty values, but in some cases, I guess they're being lazy and
forget about it.
Never guess and forget before being sure.
Originally Posted by sinclaire
I thought I just ask to see if there's an easy way to get rid of them, before I start digging into the source code
and remove them by hand.
Be sure that "digging into the source code and remove them by hand" is "lazier" than using a #define preprocessor directive.
-
February 20th, 2011, 04:34 AM
#7
Re: how to disable __FILE__ ?
Originally Posted by sinclaire
Typically, I see most people use a #define switch and set them to empty values, but in some cases, I guess they're being lazy and
forget about it.
That will not work on some compilers.
For example:
or even
Code:
#define __FILE__ ""
If you compile this with VC++2010, the compiler will issue a warning saying that __FILE__ is reserved and that it will simply ignore the #define or #undef.
-
February 20th, 2011, 07:47 AM
#8
Re: how to disable __FILE__ ?
Originally Posted by Marc G
If you compile this with VC++2010, the compiler will issue a warning saying that __FILE__ is reserved and that it will simply ignore the #define or #undef.
Good catch, Marc!
Even the old VC6.0 gives a C4117 warning then ignores #define __FILE__.
The standard states:
- The values of the predefined macros (except for_ _LINE_ _ and_ _FILE_ _) remain constant throughout the translation unit.
- If any of the predefined macro names in this subclause, or the identifier defined, is the subject of a #define or a #undef preprocessing directive, the behavior is undefined.
-
February 20th, 2011, 08:04 AM
#9
Re: how to disable __FILE__ ?
Originally Posted by sinclaire
MSVC++ 2008. I can see the full filepaths in my hex editor. I'm compiling a dynamic library (.dll) if that matters.
I thought I just ask to see if there's an easy way to get rid of them,
The easy way is to create your own define, and then do a global search and replace.
Code:
#ifdef SHOW_FILE_LINE
#define MY_FILE_MACRO __FILE__
#define MY_LINE_MACRO __LINE__
#else
#define MY_FILE_MACRO
#define MY_LINE_MACRO
#endif
And then replace __FILE_ with MY_FILE_MACRO, and __LINE__ with MY_LINE_MACRO.
Typically, I see most people use a #define switch and set them to empty values,
I have never seen this used. Who are these "most people"?
You can't undefine a compiler preprocessor symbol such as __FILE__ and __LINE__ without invoking undefined behaviour. The __FILE__ and __LINE__ macros are not only compiler macros, they are mandated by the ANSI C++ rules to perform as described -- you can't change them.
Regards,
Paul McKenzie
-
February 21st, 2011, 06:09 AM
#10
Re: how to disable __FILE__ ?
I meant the macro or function that uses __FILE__ is set to a "do nothing" state. I didn't give an example, so you assumed wrong.
Be sure that "digging into the source code and remove them by hand" is "lazier" than using a #define preprocessor directive.
On the contrary, it's not my code. I'm not obligated to fix it. I'll hack and slash as I wish.
Thanks.
-
February 21st, 2011, 06:56 AM
#11
Re: how to disable __FILE__ ?
Originally Posted by sinclaire
I meant the macro or function that uses __FILE__ is set to a "do nothing" state. I didn't give an example, so you assumed wrong.
If you have a problem, it's good to provide as much as possible details.
If you post a quiz, it's nice to specify that.
// Here is a discussion forum and not an interview.
Originally Posted by sinclaire
On the contrary, it's not my code. I'm not obligated to fix it.
Well then, don't do it!
Originally Posted by sinclaire
I'll hack and slash as I wish.
Not so fair...
You are welcome!
-
February 21st, 2011, 11:55 PM
#12
Re: how to disable __FILE__ ?
I mentioned a "define switch". This is a define switch:
Code:
#ifdef DEBUG
// do something
#else
// do nothing
#endif
I didn't say a thing about redefining __FILE___. You guys brought that up.
Thanks.
-
February 22nd, 2011, 04:04 AM
#13
Re: how to disable __FILE__ ?
Originally Posted by sinclaire
I mentioned a "define switch". This is a define switch:
Code:
#ifdef DEBUG
// do something
#else
// do nothing
#endif
I didn't say a thing about redefining __FILE___. You guys brought that up.
Thanks.
Mmm, but you wrote "I have this C++ library that uses __LINE__ and _FILE__ preprocessor directives all over the place,
and I would like to disable it or turn it off without having to explicitly remove them myself." in your first post...
Disabling or turning it off -> redefine.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|