tech-userlevel archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Use of feature test macros



On Sun, Nov 03, 2024 at 02:02:59 +0100, Roland Illig wrote:

> Am 03.11.2024 um 00:52 schrieb Robert Elz:
> >     Date:        Sat, 2 Nov 2024 22:36:10 +0100
> >     From:        Roland Illig <roland.illig%gmx.de@localhost>
> >
> >   | Is the "- 0" in the first expression really necessary? If so, for which
> >   | cases?
> >
> > When _POSIX_C_SOURCE is undefined (or defined to nothing).
> > That is the standard idiom for testing all of these feature macros.
> 
> When _POSIX_C_SOURCE (or any other identifier) is undefined, the
> preprocessor replaces it with 0. This has been spelled out in the C
> standards since C90, for example in C23 6.10.2p13, and I thought it
> would be common knowledge, that's why I didn't mention it in my original
> questions.

The idiom (though I learned it as FOO + 0, not minus) is intended to
protect you from contexts where you have in scope plain "#define FOO"
with an empty replacement list (NB: -DFOO on the command line is
different as it means -DFOO=1).  In that case "after all replacements
due to macro expansion" the FOO is no longer there and is not one of
"remaining identifiers" that "are replaced with the pp-number 0".

Now, we can argue whether _POSIX_C_SOURCE can be defined that way, but
that's how idioms are, you use them as a canned recipe so to say, so I
don't think that would be a tangential discussion at best.

-uwe


Home | Main Index | Thread Index | Old Index