3 ms·
I don’t think you are? Redefining a reserved identifier is UB per ISO C (any version) 7.1.3p2, and per 7.1.3p1, > Each macro name in [the standard library] is
by mananaysiempre 3y ago
I don’t think you are? Redefining a reserved identifier is UB per ISO C (any version) 7.1.3p2, and per 7.1.3p1,
> Each macro name in [the standard library] is reserved for use as specified if any of its associated headers is included; unless [you’re #undef’ing a function also provided as a macro].
The general idea seems to be that standard headers are allowed to use macros they define, even in other macros they define, and because macro names are late-bound (ugh), even if the user only redefines the name afterwards, every macro that uses it will then be affected.
As a silly example, a valid part of stdlib.h could be
#define NULL 0
#define EXIT_FAILURE (NULL)
#define EXIT_SUCCESS (EXIT_FAILURE+1)
and now after your redefinitions EXIT_SUCCESS becomes a constraint violation.
(For an implementor to actually do this would of course be dumb, but you did say “allowed”, and that’s what the standard says here.)
Or did I misunderstand “use as specified”?
- kazinator 3y agoDo it where it works (hopefully some platform for which you build all the time), and get your enhanced diagnostics there; avoid it where there are problems like this.