Problem with __STDC__ macro in regex.h

Sripathi Kodi sripathik@in.ibm.com
Thu Aug 25 23:48:00 GMT 2005


Hi,

I am facing a problem with the macro #if __STDC__ in usr/include/regex.h 
while using IBM's XLC++ compiler. I have explained the scenario here and 
provided what I think is the right way of using this macro in this 
header. Could you please suggest if what I am thinking is correct, so I 
can make a patch and send out.

*) /usr/include/regex.h uses __STDC__ macro to differentiate ISO C 
compliant function declarations from non-compliant type using:

#if __STDC__

# define _RE_ARGS(args) args         (conformant declarations)

#else /* not __STDC__ */

# define _RE_ARGS(args) ()           (non-conformant declarations)

#endif /* not __STDC__ */

C99 standard requires that compilers conformant to C99 predefine this 
macro to 1.

*) Both gcc and g++ are conformant to C99, so they predefine __STDC__ to 1.

*) XLC compiler is conformant to C99 standards, hence it defines 
__STDC__ to be 1. However, the XLC++ compiler (which compiles C++ code) 
is not fully C99 conformant, hence it defines __STDC__ to be 0.

*) Though XLC++ compiler is not conformant to C99, it needs to use the 
conformant type function declarations because C++ language mandates 
that. But it is not possible to access conformant type declarations 
because of the way __STDC__ macro is used in /usr/include/regex.h. Hence 
it is unable to compile C++ code on Linux.

*) There are examples of this macro being used in other ways in other 
header files, such as:
         #if defined(__STDC__) || defined(__cplusplus)

*) To enable non-C99 compliant C++ compilers to access conformant type 
declarations, this macro in regex.h needs to be changed as:

#if defined (__cplusplus) || (defined (__STDC__) && (__STDC__ == 1))

With this change:
*) Conformant compilers (gcc and g++) will not see any difference, so it 
won't break any existing code.
*) Non-C99 C compilers will still get the non-conformant type declarations.
*) C++ compilers, irrespective of whether they are C99 compliant or not, 
get access to conformant type declarations. This, I think, is what the 
macro should achieve.

Thanks and regards,
Sripathi.



More information about the Libc-alpha mailing list