staticforward and C++

Pete Shinners pete at visionart.com
Wed May 23 21:16:17 CEST 2001


"Erik Max Francis" <max at alcyone.com> wrote 
> > staticforward PyTypeObject Testtype ;
> 
> What is `staticforward'?

staticforward is a special python macro, and it is recommended
to "forward declare" your types with it (instead of just static)
for compilers that cannot handle static forward declarations...

read more here...
http://www.python.org/doc/2.1/ext/dnt-basics.html



the python headers define it here, (in object.h) ...

/*
A common programming style in Python requires the forward declaration
of static, initialized structures, e.g. for a type object that is used
by the functions whose address must be used in the initializer.
Some compilers (notably SCO ODT 3.0, I seem to remember early AIX as
well) botch this if you use the static keyword for both declarations
(they allocate two objects, and use the first, uninitialized one until
the second declaration is encountered).  Therefore, the forward
declaration should use the 'forwardstatic' keyword.  This expands to
static on most systems, but to extern on a few.  The actual storage
and name will still be static because the second declaration is
static, so no linker visible symbols will be generated.  (Standard C
compilers take offense to the extern forward declaration of a static
object, so I can't just put extern in all cases. :-( )
*/

#ifdef BAD_STATIC_FORWARD
#define staticforward extern
#define statichere static
#else /* !BAD_STATIC_FORWARD */
#define staticforward static
#define statichere static
#endif /* !BAD_STATIC_FORWARD */







More information about the Python-list mailing list