473,390 Members | 1,728 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Error: "initializer element is not constant"

Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error
"initializer element is not constant"

[ ... 3000 + lines deleted for brevity ... ]

#ifdef FILEIO
{ static struct {
char *sfn;
FILE *sfd;
} stdfiles[] = {
{"STDIN", stdin},
{"STDOUT", stdout},
{"STDERR", stderr}
};
int i;
dictword *dw;

for (i = 0; i < ELEMENTS(stdfiles); i++) {
if ((dw = atl_vardef(stdfiles[i].sfn,
2 * sizeof(stackitem))) != NULL) {
stackitem *si = atl_body(dw);
*si++ = FileSent;
*si = (stackitem) stdfiles[i].sfd;
}
}
}

[ ... to end of source file deleted for brevity ... ]

------------

and this compiler problem...

[beos@dualP2 ~/forth/atlast-1.0] $ make
cc -O -DMEMSTAT -DALIGNMENT -DEXPORT -c atlast.c -o atlast.o
atlast.c: In function `atl_init':
atlast.c:3247: initializer element is not constant
atlast.c:3247: (near initialization for `stdfiles[0].sfd')
atlast.c:3248: initializer element is not constant
atlast.c:3248: (near initialization for `stdfiles[1].sfd')
atlast.c:3249: initializer element is not constant
atlast.c:3249: (near initialization for `stdfiles[2].sfd')
make: *** [atlast.o] Error 1
I see the property list being built, and shouldnt the FILE* defined as
an element of each pair be enough to allow stdin, stdout and stderr
to be assigned? This is not my code, a package I'm porting. How
to get this to compile would be greatly appreciated, email me directly
please, I'm too ashamed to speak again here publically about this :)

Thank you!
Nov 13 '05 #1
2 19529
Todd Nathan wrote:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error
"initializer element is not constant"

[ ... 3000 + lines deleted for brevity ... ]

#ifdef FILEIO
{ static struct {
char *sfn;
FILE *sfd;
} stdfiles[] = {
{"STDIN", stdin},
{"STDOUT", stdout},
{"STDERR", stderr}
};
int i;
dictword *dw;

for (i = 0; i < ELEMENTS(stdfiles); i++) {
if ((dw = atl_vardef(stdfiles[i].sfn,
2 * sizeof(stackitem))) != NULL) {
stackitem *si = atl_body(dw);
*si++ = FileSent;
*si = (stackitem) stdfiles[i].sfd;
}
}
}

[ ... to end of source file deleted for brevity ... ]

------------

and this compiler problem...

[beos@dualP2 ~/forth/atlast-1.0] $ make
cc -O -DMEMSTAT -DALIGNMENT -DEXPORT -c atlast.c -o atlast.o
atlast.c: In function `atl_init':
atlast.c:3247: initializer element is not constant
atlast.c:3247: (near initialization for `stdfiles[0].sfd')
atlast.c:3248: initializer element is not constant
atlast.c:3248: (near initialization for `stdfiles[1].sfd')
atlast.c:3249: initializer element is not constant
atlast.c:3249: (near initialization for `stdfiles[2].sfd')
make: *** [atlast.o] Error 1
I see the property list being built, and shouldnt the FILE* defined as
an element of each pair be enough to allow stdin, stdout and stderr
to be assigned? This is not my code, a package I'm porting. How
to get this to compile would be greatly appreciated, email me directly
please, I'm too ashamed to speak again here publically about this :)

By the standard, none of stdin, stdout or stderr need necessarily be
constants -- though they are in many implementations.

HTH,
--ag

--
Artie Gold -- Austin, Texas

Nov 13 '05 #2
Todd Nathan <bi***********@yahoo.com> wrote:
Hi. have this code and compiler problem. GCC 2.95.3, BeOS, error
"initializer element is not constant"

[ ... 3000 + lines deleted for brevity ... ]

#ifdef FILEIO
{ static struct {
char *sfn;
FILE *sfd;
} stdfiles[] = {
{"STDIN", stdin},
{"STDOUT", stdout},
{"STDERR", stderr}
stdin, stdout and stderr aren't guaranteed to be compile time constants
- and you need compile time constants for aggregate initialisers.

So - the code should be written this way (this will work anywhere, so
should be fixed in the original codebase too):

{ static struct {
char *sfn;
FILE *sfd;
} stdfiles[] = {
{"STDIN", NULL },
{"STDOUT", NULL },
{"STDERR", NULL }
};

int i;
dictword *dw;

stdfiles[0].sfd = stdin;
stdfiles[1].sfd = stdout;
stdfiles[2].sfd = stderr;

/* ... */

[...] How to get this to compile would be greatly appreciated, email me
directly please, I'm too ashamed to speak again here publically about
this :)


Sorry, post here, read here - consider the next guy who comes along with
the same problem.

- Kevin.

Nov 13 '05 #3

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

Similar topics

9
by: Player | last post by:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello all. I am in the process of teaching myself C# and I think I am doing OK. I have learnt how to how to call the right constructor of a...
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 element is not constant foo.c: error: (near...
1
by: tankbattle | last post by:
That is, what's the difference between <complexType name="Address" final="restriction"> <sequence> <element name="name" type="string"/> <element name="street" type="string"/> <element...
2
montzter
by: montzter | last post by:
Hi, Got some declarations below but when I compiled it I got the above mentioned error. 1. I'd like to know if my implementation or stucture is doable. 2. How could i fix the problem...?...
4
by: jaime | last post by:
Hi again all. Given the line: const int x=5; Can I then use "x" as a constant expression? (By "constant expression", I mean "constant expression" as defined in the C99 standard) I've been...
2
by: hankypan1 | last post by:
Hi All, I need a tree data structure for my application. It is the non - cyclic simple tree where i can have any number of children node and each child can recursively become a sub tree like a...
13
by: bobg.hahc | last post by:
running access 2k; And before anything else is said - "Yes, Virginia, I know you can NOT use a variable to set a constant (that's why it's constant)". BUT - my problem is - I want a constant,...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
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 up as follows, but get the "initializer element...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.