G
Gowtham
Hi,
I had some C code written which initialized a global variable as:
FILE *yyerfp = stdout;
This used to work fine in older versions of gcc. Now, when I tried to
compile this code (with gcc 3.2.3),
I got errors like:
.../Include/Message.h:42: initializer element is not constant
I looked around the www and found that stdin/stdout/stderr are *not*
made const in the newer
versions of gcc.
As a work-around, I thought of this:
FILE *yyerfp; // Uninitialized global
// Initialize it in a separate function
void initializeGlobals( void )
{
yyerfp = stdout;
}
int main( ... )
{
// Initialize the global before doing anything else
initializeGlobals();
...
// Do other things
}
But, this code will also be compiled into a shared object, dynamically
loadable from other
languages such as perl etc. and I do not want to change the API
interface there. If I follow
this approach, I also have to add the initializeGlobals() call in
every perl program which uses
this library.
What is the best way of solving this problem?
Thanks
Gowtham
I had some C code written which initialized a global variable as:
FILE *yyerfp = stdout;
This used to work fine in older versions of gcc. Now, when I tried to
compile this code (with gcc 3.2.3),
I got errors like:
.../Include/Message.h:42: initializer element is not constant
I looked around the www and found that stdin/stdout/stderr are *not*
made const in the newer
versions of gcc.
As a work-around, I thought of this:
FILE *yyerfp; // Uninitialized global
// Initialize it in a separate function
void initializeGlobals( void )
{
yyerfp = stdout;
}
int main( ... )
{
// Initialize the global before doing anything else
initializeGlobals();
...
// Do other things
}
But, this code will also be compiled into a shared object, dynamically
loadable from other
languages such as perl etc. and I do not want to change the API
interface there. If I follow
this approach, I also have to add the initializeGlobals() call in
every perl program which uses
this library.
What is the best way of solving this problem?
Thanks
Gowtham