Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C > Handling 'initi...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 17 Topic 26103 of 26198
Post > Topic >>

Handling 'initializer element not constant' error

by Gowtham <gowthamgowtham@[EMAIL PROTECTED] > May 7, 2008 at 07:14 AM

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




 17 Posts in Topic:
Handling 'initializer element not constant' error
Gowtham <gowthamgowtha  2008-05-07 07:14:35 
Re: Handling 'initializer element not constant' error
viza <tom.viza@[EMAIL   2008-05-07 07:43:00 
Re: Handling 'initializer element not constant' error
Willem <willem@[EMAIL   2008-05-07 15:20:02 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 17:01:29 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 10:29:14 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 19:21:06 
Re: Handling 'initializer element not constant' error
Keith Thompson <kst-u@  2008-05-07 13:38:56 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 10:31:30 
Re: Handling 'initializer element not constant' error
vippstar@[EMAIL PROTECTED  2008-05-07 13:49:08 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 22:29:06 
Re: Handling 'initializer element not constant' error
Ben Pfaff <blp@[EMAIL   2008-05-07 15:30:43 
Re: Handling 'initializer element not constant' error
richard@[EMAIL PROTECTED]  2008-05-07 22:40:52 
Re: Handling 'initializer element not constant' error
Ben Pfaff <blp@[EMAIL   2008-05-07 15:46:39 
Re: Handling 'initializer element not constant' error
dj3vande@[EMAIL PROTECTED  2008-05-07 22:44:24 
Re: Handling 'initializer element not constant' error
Flash Gordon <spam@[EM  2008-05-08 06:56:18 
Re: Handling 'initializer element not constant' error
Peter Nilsson <airia@[  2008-05-07 15:20:10 
Re: Handling 'initializer element not constant' error
Szabolcs Borsanyi <bor  2008-05-09 02:32:49 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue May 13 14:54:43 CDT 2008.