Re: Use of feature test macros

David Holland <[email protected]>
Newsgroups gmane.os.netbsd.devel.userlevel
Message-ID <[email protected]>
On Sat, Nov 02, 2024 at 10:36:10PM +0100, Roland Illig wrote:
 > In the system headers, we use this pattern a lot:
 > > #if (_POSIX_C_SOURCE - 0 >= 200809L) || defined(_NETBSD_SOURCE)
 > 
 > Are the parentheses around the first condition really necessary? If so,
 > for which cases?
 > 
 > Is the "- 0" in the first expression really necessary? If so, for which
 > cases?

I was just discussing this idiom a few days ago, in the context of
program checkers that warn when you do #if SYM when it isn't defined
(which is legal and well defined, but also often a mistake) and one of
the virtues of this idiom is that such checkers can recognize it and
shut up.

For that purpose it's better to keep the parentheses as well as the
arithmetic.

-- 
David A. Holland
[email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.