Loading a C++ interface

Collette Yann ycollette at free.fr
Fri Jul 11 08:16:43 CEST 2008


Hello,

I've wrote a C++ interface (for the CLP linear programming).
To allow the loading of this C++ interface, I must declare the function 
prototype like this:

extern "C"
{
include <stack-c.h>
}

extern "C" int C2F(sciclp)(char * fname);

int C2F(sciclp)(char * fname)
{
.....

Once I have done this, I must #undef some macros because g++ (starting 
from version 3.3) refuse to cast integer * into void *:

#undef CreateVar
#define CreateVar(n,ct,mx,nx,lx) if(! 
C2F(createvar)((c_local=n,&c_local),ct,mx,nx,lx, 1L)) { return 0;  }

#undef CreateListVarFrom
#define CreateListVarFrom(n,m,ct,mx,nx,lx,lx1) if 
(!C2F(createlistvarfrom)((c_local=n,&c_local),(c1_local=m,&c1_local),ct,mx,nx,lx,lx1,1L))  
{ return 0;}

These new macros just remove the cast to void *.

Now, I switched to g++-4.2.1 and I've got a huge number of warning due 
to a cast between const char * and char *.

So, my questions are:
- are these cast to void * in stack-c.h really necessary ?
- is it safe to switch the prototype of createvar and createlistvarfrom 
to const char * instead of char * ?

YC



More information about the dev mailing list