This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: enum and macro collision


On 17 January 2017 at 11:03, vijay nag wrote:
> Hello Gcc,
>
> I came across this nasty C code of an enumerator and a macro having
> the same name. Although this is a buggy code, I found it surprising
> that GCC compiles in one of the cases(snippet 1) while in the other
> compiler flags an error(snippet 2). Would be interested to know  why
> the order of definitions/declarations matter and what C standards the
> compiler is adhering to ?

Just look at the preprocessed code, it should be obvious.

Macros aren't defined until they're defined.

When the macro is defined after the enumerator it can't change it and
you get a valid enumerator definition, FOO = 1.

When the macro is defined earlier it produces an invalid enumerator,
0xDEADBEEF = 1

What isn't clear?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]