[Python-Dev] use of #pragma GCC system_header to
suppress _XOPEN_SOURCE warnings
Skip Montanaro
skip at pobox.com
Fri Aug 6 21:45:43 CEST 2004
>> Unfortunately GCC also defines it, so a "macro redefined" warning is
>> emitted when compiling with GCC and including Python.h.
Martin> That is not true. GCC does not define that macro, on any
Martin> platform.
I was shown today that g++ defines that macro internally (I misspoke when I
referred to gcc yesterday - I tend to lump them together and forget that C++
is a different language than C), at least 3.3.2 on Solaris/Intel does.
Given this small source file:
#include "Python.h"
int main() {
printf("%x\n", PyList_GetItem);
return 0;
}
compilation with gcc (we're using 3.3.2, but I also tried with 3.4.0)
produces no warnings, but compilation with g++ it produces this output:
g++ -I/opt/lang/python/include/python2.3 -c example.c
In file included from /opt/lang/python/include/python2.3/Python.h:8,
from example.c:2:
/opt/lang/python/include/python2.3/pyconfig.h:862:1: warning: "_XOPEN_SOURCE" redefined
<built-in>:73:1: warning: this is the location of the previous definition
Sure enough, grepping through the gcc/g++ installation directory doesn't
turn up an actual header file containing "#define _XOPEN_SOURCE". I did
find a file (.../lib/gcc/i386-pc-solaris2.8/3.4.0/install-tools/
mkheaders.conf) that contains this line:
FIXPROTO_DEFINES="-D_XOPEN_SOURCE"
Martin> Some system header may define it, though. I believe this is a
Martin> bug in the system - the macro *should* be defined in the
Martin> application. What system are you referring to, and where does
Martin> that define _XOPEN_SOURCE? Is that definition conditional?
Does the fact that we're talking g++ and a built-in macro instead of gcc and
a macro defined in a .h file suggest a different way to suppress this
warning?
A little more searching located the standards(5) man page on the system. In
part it says:
X/Open CAE
To build or compile an application that conforms to one of
the X/Open CAE specifications, use the following guidelines.
Applications need not set the POSIX feature test macros if
they require both CAE and POSIX functionality.
...
SUSv2 The application must define _XOPEN_SOURCE=500.
This suggests that Sun expects the application or its build tools to define
_XOPEN_SOURCE, not the compiler or its header files. That suggests a bug in
g++.
Skip
More information about the Python-Dev
mailing list