[Python-Dev] Forward declaration of PyObject* values

Tom Emerson tree at basistech.com
Wed Aug 13 16:57:02 EDT 2003


I'm working on an application (in C++) that conditionally embeds
Python. Some of the (C++) classes include PyObject*'s only when
embedding Python. In other cases these aren't here. I do not want to
include Python.h in the header files for these classes because not all
of the clients of these classes use the Python functionality.

Hence I would like to forward declare PyObject so it can be used as an
opaque type in these interfaces, and only have Python.h included in
those source files that actually need it.

This comes up because Python.h needs to be included before any system
interfaces, lest you get various compiler warnings (cf. sf issue
637321 related to the redefinition of _POSIX_C_SOURCE) but

struct PyObject;

doesn't work, at least in GCC 3.2.2:

../include/bt_notice.h:31: conflicting types for `struct PyObject'
../../../third-party-tools/python/include/python2.3/object.h:104: previous 
   declaration as `typedef struct _object PyObject'
make: *** [obj_g/RH72-gcc-3.2/bt_notice.o] Error 1

Since I would rather not have to include Python.h in every source file
that could possible include the headers that reference PyObject*'s,
I'm looking for a way to avoid these warnings. I expect there is none,
but...

Thanks in advance.

    -tree

-- 
Tom Emerson                                          Basis Technology Corp.
Software Architect                                 http://www.basistech.com
  "Beware the lollipop of mediocrity: lick it once and you suck forever"



More information about the Python-Dev mailing list