Users of Clang plus glibc, beware

On the one hand, Clang conservatively (and somewhat shizophrenically) claims it is GCC 4.2, by predefining __GNUC__ = 4 and __GNUC_MINOR__ = 2.

On the other hand, glibc headers contain a number of conditional blocks that are only activated for specific GCC versions, using a macro __GNUC_PREREQ(maj, min) that internally checks against __GNUC__ and __GNUC_MINOR__.

For example, that macro is used (for whatever reason) to control whether wchar.h defines the two C++-mandated overloads

wchar_t * wcschr(wchar_t * wcs, wchar_t wc);
wchar_t const * wcschr(wchar_t const * wcs, wchar_t wc);

or the single C-mandated but const-unsafe

wchar_t * wcschr(wchar_t const * wcs, wchar_t wc);

even in __cplusplus mode.

So be warned and do not leave broken code behind, as with “Missing const.”

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s