Is it possible to tell GCC to compile the source code, and ignore macros like __FILE__
, __LINE__
, etc, etc, or redefine them to expand into let's say - an empty string?
Ignoring or redefining GCC Standard Predefined Macros
Asked Answered
As with any macro you can just use:
#undef __LINE__
#undef __FILE__
and then you can redefine them.
You can also pass -U macroname
to undef a macro name and -D macroname=definition
to define a macro name to the gcc
options.
Note that, as indicated in another answer, undefining or redefining __LINE__
or __FILE__
in C invokes undefined behavior.
I suspect doing so provokes UB. Please see my answer on this. –
Pyramidal
@Pyramidal but I think the relevant quote is this one: (c99, 6.10.8p4) "None of these macro names, nor the identifier defined, shall be the subject of a #define or a #undef preprocessing directive. –
Joanejoanie
Hm, yes, found this too .. but UB isn't mentioned in this context. –
Pyramidal
@Pyramidal violation of a shall requirement that is not a constraint in C invokes UB, see C99, 4.p2 –
Joanejoanie
It would probably be better if it'd be a constraint violation. Implementing a check for that at compilation time should not be big deal. –
Neckar
@Pyramidal I see that the current C standard is C11. Is C99 accurate/up-to-date enough to be used in most cases? P.S. I don't want to spend $30 USD on the new standard. –
Diu
@BitFiddlingCodeMonkey: I doubt there are many essential changes (not additions) from C99 to C11 which aren't backward compatible. However this is an assumption of mine ... - Details: en.wikipedia.org/wiki/C11_%28C_standard_revision%29 –
Pyramidal
© 2022 - 2024 — McMap. All rights reserved.
__LINE__
with like0
or-1
would look awkward (It's an integer value and you have to give something, unlike empty string for__FILE__
) 3. Their primary purpose is to help debug (If you don't want them, why use them in the first place?). So it seems the only way is to re-write your code if you don't want them or better keep them! – Prestissimo