Ignore or override standard GCC predefined macros

Is it possible to tell GCC to compile the source code and ignore macros such as __FILE__ , __LINE__ , etc., etc., or override them for extension in let say - an empty line?

+6
source share
1 answer

Like any macro, you can simply use:

 #undef __LINE__ #undef __FILE__ 

and then you can override them.

You can also pass -U macroname to undef the macro name and -D macroname=definition to specify the macro name for gcc options.

Note that, as pointed out in another answer, undefining or redefining __LINE__ or __FILE__ in C causes undefined behavior.

+5
source

All Articles