[Python-Dev] Forward declaration of PyObject* values

Scott Gilbert xscottg at yahoo.com
Wed Aug 13 14:15:59 EDT 2003

I used the following for a similar task:

#ifndef PyObject_HEAD
struct _object;
typedef _object PyObject;

Some compilers won't like the incomplete type on the struct, but it looks
like you're using GCC which should be fine.

Since PyObject_HEAD is defined in object.h, you won't be redefining it if
the actual file is really included.  This is probably fragile, but so is
using a leading underscore in a user defined type, or having a name as
generic as _object at the global scope.  It works for now at least.

--- Tom Emerson <tree at basistech.com> wrote:
> [...] 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.

More information about the Python-Dev mailing list