Re:GCC 13 Supports New C2x Features, Including Nullptr, Enha...
by kazinator on Monday May 15, 2023 @02:51PM
(#35952861)
You're allowed to do:
Just don't do it prior to the inclusion of any standard header (C or POSIX).
[ Parent
| on HN ]
Re:GCC 13 Supports New C2x Features, Including Nullptr, Enha...
by mananaysiempre on Monday May 15, 2023 @03:46PM
(#35953511)
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, 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”?