<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>We recently upgraded
our GCC tool set to 3.2.1 from 2.95.2. I have written a C++
module</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>to parse STDF
binary test data files and return the data in python objects. With the
older</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>compiler, including
G++, the 'staticforward' and 'statichere' macros functioned without
incident;</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>I was able
</SPAN></FONT><FONT face=Arial size=2><SPAN class=570382020-06032003>to link
python by specifying the linker as (CXX). The new </SPAN></FONT><FONT
face=Arial size=2><SPAN class=570382020-06032003>G++ (3.2.1) bails on
compilation,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>complaining
</SPAN></FONT><FONT face=Arial size=2><SPAN class=570382020-06032003>about
re-definition of the static vars. Without posting the whole content of
</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>the module, I was
able to work around it in a manner similar to the following
examples,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>which can be
compiled standalone to demo the problem. You don't need extern "C"
in</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>these examples. If
any python guru has a more elegant workaround than the
following,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>please let me
know.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003> ---- CUT
BROKEN ----</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Do nothing demo
of GCC vs. G++ and Python. This works<BR> with GCC, but G++
won't compile it. G++ bails on the<BR> redefinition of static vars.
MR I Have to use G++ to<BR> link Python, because my python module is
written <BR> in C++. The older G++ (2.95.2) did not have a
problem<BR> with this. */</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>#include
<stdio.h></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Python predefines
some macros and types like these */<BR>#define staticforward static<BR>#define
statichere static</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Define an
arbitrary structure type (Like PyMethodDef) */<BR>typedef struct ADef
{<BR> int dummy;<BR> void (*af)(int
i);<BR>}ADef;</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Pre-declare a
static array because we need to refer to<BR> it, prior to its
definition. Similar to Python's method arrays */<BR>static ADef
sarr[2];</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Create some void
funcs which refer to the sarr */<BR>static void bfunc(int i)<BR>{<BR>
printf("bfunc: sarr[%d] dummy is
%d\n",i,sarr[i].dummy);<BR>}</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>static void
cfunc(int i)<BR>{<BR> printf("cfunc: sarr[%d] dummy is
%d\n",i,sarr[i].dummy);<BR>}</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Define the
previously declared static array<BR> including the funcs in the
definition. */<BR>statichere ADef sarr[2] = {<BR> { 12, bfunc
},<BR> { 24, cfunc }<BR>};</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>main(int argc, char
*argv[])<BR>{<BR> sarr[0].af(1);<BR>
sarr[1].af(0);<BR>}</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003> </DIV>
<DIV><BR>---- CUT END BROKEN ----</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>---- CUT FIXED
----</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/*<BR> Do
nothing demo of GCC vs. G++ and Python. This works<BR> with G++ and hacks
around the problem at run time at the cost<BR> of an additional static
ptr. I turns out Python has to<BR> call my module's init() process
anyway.<BR> */</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>#include
<stdio.h></SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* An arbitrary
structure */<BR>typedef struct ADef {<BR> int dummy;<BR> void
(*af)(int i);<BR>}ADef;</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Pre-declare a
pointer to a static array, which will<BR> be assigned at
runtime. */<BR>static ADef *sarr_ptr;</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Create some void
funcs which refer to the sarr */<BR>static void bfunc(int i)<BR>{<BR>
printf("bfunc: sarr[%d] dummy is
%d\n",i,sarr_ptr[i].dummy);<BR>}</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>static void
cfunc(int i)<BR>{<BR> printf("cfunc: sarr[%d] dummy is
%d\n",i,sarr_ptr[i].dummy);<BR>}</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>/* Define the
previously declared static array<BR> including the funcs in the
definition. */<BR>static ADef sarr[2] = {<BR> { 12, bfunc
},<BR> { 24, cfunc }<BR>};</SPAN></FONT></DIV>
<DIV> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>main(int argc, char
*argv[])<BR>{<BR> /* In the python module's initmodulename()
function,<BR> I added lines similar to this line for the
Obj method arrays etc. */<BR> sarr_ptr = sarr;<BR>
/**/</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>
sarr[0].af(1);<BR> sarr[1].af(0);<BR>}<BR></SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>---- CUT END
FIXED -----</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>Is this solution the
proper one? If not, are there any switches etc. I should use
with</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003>G++ to get it to act
properly.</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003></SPAN></FONT> </DIV>
<DIV><FONT face=Arial size=2><SPAN
class=570382020-06032003>Regards,</SPAN></FONT></DIV>
<DIV><FONT face=Arial size=2><SPAN class=570382020-06032003> M.
Riendeau</SPAN></FONT></DIV>
<P><FONT face=ADILogo size=2>-</FONT> </P>
<P><FONT face="Courier New" size=2>Michael H. Riendeau</FONT> <BR><FONT
face="Courier New" size=2>Staff Test Engineer</FONT> <BR><SPAN
class=570382020-06032003><FONT face="Courier New" size=2>Analog Devices ATE
Products Group</FONT></SPAN></P>
<P><SPAN class=570382020-06032003></SPAN><FONT face="Courier New"><FONT
size=2><A href="http://www.analog.com">http://www.analog.c<SPAN
class=570382020-06032003>om</A></SPAN></FONT></FONT></P>
<DIV><FONT face=Arial size=2></FONT> </DIV></BODY></HTML>