472,352 Members | 1,497 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,352 software developers and data experts.

what's meaning of "warning: initializer element is not computable at load time"

I have some codes generated by perl, in which initialize some huge
struct,such as

PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "",
"configuration on a designated vlan", PRO_REQUIRED };
const char* TOS_network_spantree_set_0_para_1_emvalue[] = { "disable",
"enable", NULL };
PARA TOS_network_spantree_set_0_para_1 = { "", emENUM,
TOS_network_spantree_set_0_para_1_emvalue, "", "enable or disable STP",
PRO_REQUIRED };
PPARA TOS_network_spantree_set_0_para[] = {
&TOS_network_spantree_set_0_para_0,
&TOS_network_spantree_set_0_para_1,
NULL
}
......

gcc(C89 setting) report warnings about that, but C99 not. I ignore those
warnings and try to dump the struct, the program crashed after some output.
what wrong and how I can fix it?

thanks a lot
Nov 14 '05 #1
4 3919
On Wed, 1 Jun 2005 14:17:01 +0800, "bingfeng"
<zh***********@topsec.com.cn> wrote in comp.lang.c:
I have some codes generated by perl, in which initialize some huge
struct,such as
PERL is off-topic here, and your code snippet is littered with types
not defined by C, so it is hard to tell.
PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "",
What is the definition of the type 'PARA'? It appears to be 'pointer
to pointer to char' or 'pointer to pointer to const char'.
"configuration on a designated vlan", PRO_REQUIRED };
const char* TOS_network_spantree_set_0_para_1_emvalue[] = { "disable",
"enable", NULL };
PARA TOS_network_spantree_set_0_para_1 = { "", emENUM,
TOS_network_spantree_set_0_para_1_emvalue, "", "enable or disable STP",
If I am right about the definition of 'PARA', the initialization of is
wrong. "" and "enable or disable STP" are string literals, but
'TOS_network_spantree_set_0_para_1_emvalue' decays into a pointer to
pointer to char, a different type.
PRO_REQUIRED };
PPARA TOS_network_spantree_set_0_para[] = {
&TOS_network_spantree_set_0_para_0,
&TOS_network_spantree_set_0_para_1,
NULL
}
......

gcc(C89 setting) report warnings about that, but C99 not. I ignore those
warnings and try to dump the struct, the program crashed after some output.
what wrong and how I can fix it?

thanks a lot


I would say you have two options, one is to post the definitions of
all the UPPER CASE types and values used in the code snippet. The
other is to talk to the person who wrote the PERL code that generates
this, as it seems to be incorrect.

By the way, it is a very good idea indicate the exact line of your
code snippet that the compiler indicated was the cause of the error.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
Jack Klein <ja*******@spamcop.net> wrote:
On Wed, 1 Jun 2005 14:17:01 +0800, "bingfeng"
<zh***********@topsec.com.cn> wrote in comp.lang.c:
gcc(C89 setting) report warnings about that, but C99 not. I ignore those
warnings and try to dump the struct, the program crashed after some output.
what wrong and how I can fix it?
I would say you have two options, one is to post the definitions of
all the UPPER CASE types and values used in the code snippet.

By the way, it is a very good idea indicate the exact line of your
code snippet that the compiler indicated was the cause of the error.


_And_ the exact text of the warning itself. It could warn about
"incompatible types" or about "uninitialised objects" or about "your
indentation style is ugly", and the solution would be different in each
case.

Richard
Nov 14 '05 #3
>> On Wed, 1 Jun 2005 14:17:01 +0800, "bingfeng"
<zh***********@topsec.com.cn> wrote in comp.lang.c:
gcc(C89 setting) report warnings about that, but C99 not. I ignore
those warnings and try to dump the struct, the program crashed after
some output. what wrong and how I can fix it?
Jack Klein <ja*******@spamcop.net> wrote:
I would say you have two options, one is to post the definitions of
all the UPPER CASE types and values used in the code snippet.

Indeed -- although I suspect the problem causing the crash is something
else entirely.
By the way, it is a very good idea indicate the exact line of your
code snippet that the compiler indicated was the cause of the error.


In article <42***************@news.xs4all.nl>,
Richard Bos <rl*@hoekstra-uitgeverij.nl> wrote:_And_ the exact text of the warning itself. It could warn about
"incompatible types" or about "uninitialised objects" or about "your
indentation style is ugly", and the solution would be different in each
case.


As it happens, the exact text of the warning is in the "subject"
header line. But this is not always visible to everyone when
reading the message body, so it should be repeated in (or moved
to) the message body:

"warning: initializer element is not computable at load time"

This particular warning is one that GCC emits when you use GCC's
C89-extension that allows initializing aggregates with non-constant
values. For instance:

% cat t.c
void f(int x, int y) {
int a[2] = { x, y };
...
}

This code is allowed in C99, but not in C89. GCC allows it even
without -std=c99, but will issue a diagnostic when requested:

% cc -O2 -c -W -Wall t.c
% cc -ansi -pedantic -O2 -c t.c
t.c: In function `f':
t.c:3: warning: initializer element is not computable at load time
t.c:3: warning: initializer element is not computable at load time
% cc -std=c99 -pedantic -O2 -c t.c
%

(note that "-ansi" means the same as "-std=c89", and "-pedantic"
is the option that tells GCC to emit the required diagnostic).
--
In-Real-Life: Chris Torek, Wind River Systems
Salt Lake City, UT, USA (4039.22'N, 11150.29'W) +1 801 277 2603
email: forget about it http://web.torek.net/torek/index.html
Reading email is like searching for food in the garbage, thanks to spammers.
Nov 14 '05 #4
thanks to all warmhearted persons at first!

I know the exact answer of that question: I initialized a huge struct in a
function then return the address of struct to caller! Auto variables are not
stored in static memory, so loader cannot load it properly. Of course, it's
a fundamental to use static variables in such case, but the parts are in
global at first. I didn't want to introduce too many global names to global
namespace, and it seems initialize such struct is impossible, so I move it
into a function scope and emit add static keyword(you know, all the code was
generated automatic by some other tool). The difference of result C89, C99
and C++
generated misled I compare the different features they supported, sigh!

As to the coredump, someone told me maybe too many local variables occupy a
lot of stack, and my test routine use recursive calls, all of that in eacess
of size of stack, so app crashed. I think him is right.

If gcc mention "local variable" or "auto variable", I would notice such
basic and important bug, but I spend four hours before I ask others view my
code!
"Jack Klein" <ja*******@spamcop.net> ????
news:cg********************************@4ax.com...
On Wed, 1 Jun 2005 14:17:01 +0800, "bingfeng"
<zh***********@topsec.com.cn> wrote in comp.lang.c:
I have some codes generated by perl, in which initialize some huge
struct,such as


PERL is off-topic here, and your code snippet is littered with types
not defined by C, so it is hard to tell.
PARA TOS_network_spantree_set_0_para_0 = { "vlan", emNUM, NULL, "",


What is the definition of the type 'PARA'? It appears to be 'pointer
to pointer to char' or 'pointer to pointer to const char'.
"configuration on a designated vlan", PRO_REQUIRED };
const char* TOS_network_spantree_set_0_para_1_emvalue[] = { "disable", "enable", NULL };
PARA TOS_network_spantree_set_0_para_1 = { "", emENUM,
TOS_network_spantree_set_0_para_1_emvalue, "", "enable or disable STP",


If I am right about the definition of 'PARA', the initialization of is
wrong. "" and "enable or disable STP" are string literals, but
'TOS_network_spantree_set_0_para_1_emvalue' decays into a pointer to
pointer to char, a different type.
PRO_REQUIRED };
PPARA TOS_network_spantree_set_0_para[] = {
&TOS_network_spantree_set_0_para_0,
&TOS_network_spantree_set_0_para_1,
NULL
}
......

gcc(C89 setting) report warnings about that, but C99 not. I ignore those
warnings and try to dump the struct, the program crashed after some output. what wrong and how I can fix it?

thanks a lot


I would say you have two options, one is to post the definitions of
all the UPPER CASE types and values used in the code snippet. The
other is to talk to the person who wrote the PERL code that generates
this, as it seems to be incorrect.

By the way, it is a very good idea indicate the exact line of your
code snippet that the compiler indicated was the cause of the error.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html

Nov 14 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Carl Owenby | last post by:
Re: Microsoft Knowledge Base Article - 174942 "File Modified Outside Source Editor" Warning Message I believe I have discovered a cause of this...
2
by: Todd Nathan | last post by:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error "initializer element is not constant" #ifdef FILEIO { static struct {...
40
by: Dave Hansen | last post by:
Please note crosspost. Often when writing code requiring function pointers, it is necessary to write functions that ignore their formal...
3
by: Chuck Cobb | last post by:
I'm doing a CSharp project in VS2005 and I'm getting some strange warning messages. The problem is that the warning messages don't link to anything...
19
by: lawrence k | last post by:
How can I find out where my script is outputting to the screen for the first time? My error logs are full of stuff like this: PHP Warning: ...
1
by: emin.martinian | last post by:
When trying to compile python extensions written in C using "python setup.py build" on cygwin I get the following error: foo.c: initializer...
1
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/>...
7
by: Zhang Weiwu | last post by:
Dear all How does javascript realiablily tell if a variable is a reference to an HTML Element "<select>", without causing browser to pop up error...
3
by: zoeb | last post by:
Hi, I am declaring an array which carries x coordinates, however these will vary depending on the geometry the user enters. I have set my code...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: teenabhardwaj | last post by:
How would one discover a valid source for learning news, comfort, and help for engineering designs? Covering through piles of books takes a lot of...
1
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
0
by: AndyPSV | last post by:
HOW CAN I CREATE AN AI with an .executable file that would suck all files in the folder and on my computerHOW CAN I CREATE AN AI with an .executable...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.