Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Wed, 29 Aug 2012 13:17:48 -0400
From: Gregor Richards <gr@...due.edu>
To: musl@...ts.openwall.com
Subject: Re: Re: Best bikeshed ever (feature test macros)

On 08/29/2012 11:23 AM, Rich Felker wrote:
> For example, if you want the kitchen
> sink on some (most?) BSDs, the only way to get it is to omit all
> feature test macros entirely

I need to echo this sentiment, because it's important:

If you use only POSIX, then feature test macros are great. They behave 
the same everywhere and give you exactly what you want.

If you use ANY EXTENSIONS WHATSOEVER, then adding feature test macros 
WILL ASSUREDLY BREAK YOUR PROGRAM on some libc. The implementation is 
simply not consistent. The fact is, that if you want your program to be 
portable, but it requires extensions (this is not an oxymoron), then the 
proper way to go is to check for those extensions with something like 
autoconf, and then never ever set feature test macros. It's probably 
even worse than you think: The only way to figure out where or how it 
breaks your code is to try it everywhere. Thought setting _BSD_SOURCE 
was enough? Nope, you'll need at least __BSD_VISIBLE (which you're not 
supposed to touch), __EXTENSIONS__ and _DARWIN_C_SOURCE. If the feature 
test macro does not correspond to a standard, then it is a very 
effective way to shoot yourself in the foot.

Just to make this perfectly clear: If you are writing a portable program 
that, under any circumstances, uses some extension beyond POSIX, then 
adding feature test macros will break your code.

The code out there without feature test macros is not broken; it's 
portable. You can whine and moan about that state of affairs as much as 
you want, but if you actually want software to work on musl /and/ some 
other libc, then you must support this configuration.

(Please note that, in direct response to the statement I'm quoting, 
FreeBSD and Solaris are the only libcs I know of at this time that 
provide no way beyond hacks to get “the kitchen sink” back after setting 
feature test macros. You need to set at least _BSD_SOURCE, _SVID_SOURCE 
and _DARWIN_C_SOURCE to get the kitchen sink back on those that do 
support nonstandard feature test macros.)

With valediction,
  - Gregor Richards


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.