This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with __STDC__ macro in regex.h


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]