473,326 Members | 2,111 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,326 software developers and data experts.

problem compiling related to extern

I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html

This is quite a complicated program that involves several .c files

I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant

This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;

It is part of many lines of stuff that occur before main()

hullmain.c includes hull.h, and in hull.h I find:
FILE* efopen(char *, char *);
extern FILE *DFILE;

I think the mysterious "initializer element" error is related to
*DFILE = stderr
in hullmain.c

If I remove this bit I can get the program to compile (but it segfaults
when I run it :-)

What is the proper way to initialize the pointer *DFILE to be stderr?

If anyone can offer any tips on what is wrong and how to correct it,
I'd greatly appreciate it.

Thanks!
Bill

Nov 14 '05 #1
6 1449
johnnie...@techie.com wrote:
I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html

This is quite a complicated program that involves several .c files

I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant

This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;

It is part of many lines of stuff that occur before main()

hullmain.c includes hull.h, and in hull.h I find:
FILE* efopen(char *, char *);
extern FILE *DFILE;

I think the mysterious "initializer element" error is related to
*DFILE = stderr
in hullmain.c

If I remove this bit I can get the program to compile (but it segfaults when I run it :-)

What is the proper way to initialize the pointer *DFILE to be stderr?

If anyone can offer any tips on what is wrong and how to correct it,
I'd greatly appreciate it.

Thanks!
Bill


On some systems stderr is not a constant. The correct way to do this
would be to move the _initialization_ to main before DFILE is used.

Rob Gamble

Nov 14 '05 #2


jo********@techie.com wrote:
I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html

This is quite a complicated program that involves several .c files

I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant

This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;

It is part of many lines of stuff that occur before main()

hullmain.c includes hull.h, and in hull.h I find:
FILE* efopen(char *, char *);
extern FILE *DFILE;

I think the mysterious "initializer element" error is related to
*DFILE = stderr
in hullmain.c
You're right. The initializer for a file-scope variable
(or for a function-local `static' variable) must be a compile-
time constant, because it must produce its value before the
program actually starts running. All three `stdxxx' streams
are predefined by the implementation, but on some implementations
their definitions are not compile-time constants. Hence the
error.
If I remove this bit I can get the program to compile (but it segfaults
when I run it :-)
At a guess, this is because the program tries to use DFILE,
expecting it to be a valid `FILE*' pointer -- but without an
initiazlizer, DFILE will be initialized to NULL ...
What is the proper way to initialize the pointer *DFILE to be stderr?

If anyone can offer any tips on what is wrong and how to correct it,
I'd greatly appreciate it.


"Initialize" DFILE by assigning to it before it is used,
probably very early in main():

FILE *DFILE;
int main(...) {
DFILE = stderr;
...
}

An alternative approach would be to define DFILE as a macro
that expands to stderr:

/* FILE *DFILE = stderr; -- removed */
#define DFILE stderr

--
Er*********@sun.com

Nov 14 '05 #3
Eric Sosman wrote:
jo********@techie.com wrote:
I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html

This is quite a complicated program that involves several .c files

I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant

This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;

It is part of many lines of stuff that occur before main()

hullmain.c includes hull.h, and in hull.h I find:
FILE* efopen(char *, char *);
extern FILE *DFILE;

I think the mysterious "initializer element" error is related to
*DFILE = stderr
in hullmain.c


You're right. The initializer for a file-scope variable
(or for a function-local `static' variable) must be a compile-
time constant, because it must produce its value before the
program actually starts running. All three `stdxxx' streams
are predefined by the implementation, but on some implementations
their definitions are not compile-time constants. Hence the
error.
If I remove this bit I can get the program to compile (but it segfaults when I run it :-)


At a guess, this is because the program tries to use DFILE,
expecting it to be a valid `FILE*' pointer -- but without an
initiazlizer, DFILE will be initialized to NULL ...
What is the proper way to initialize the pointer *DFILE to be stderr?
If anyone can offer any tips on what is wrong and how to correct it, I'd greatly appreciate it.


"Initialize" DFILE by assigning to it before it is used,
probably very early in main():

FILE *DFILE;
int main(...) {
DFILE = stderr;
...
}

An alternative approach would be to define DFILE as a macro
that expands to stderr:

/* FILE *DFILE = stderr; -- removed */
#define DFILE stderr


Of course if the program ever attempts to modify DFILE this would cause
a problem.

Rob Gamble

Nov 14 '05 #4
jo********@techie.com wrote:
I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html

This is quite a complicated program that involves several .c files

I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant

This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;

It is part of many lines of stuff that occur before main()

hullmain.c includes hull.h, and in hull.h I find:
FILE* efopen(char *, char *);
extern FILE *DFILE;

I think the mysterious "initializer element" error is related to
*DFILE = stderr
in hullmain.c

If I remove this bit I can get the program to compile (but it segfaults
when I run it :-)

What is the proper way to initialize the pointer *DFILE to be stderr?

If anyone can offer any tips on what is wrong and how to correct it,
I'd greatly appreciate it.

Thanks!
Bill


Probably because we can't find stdio.h where stderr is '#define'ed.
--
Joe Wright mailto:jo********@comcast.net
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Nov 14 '05 #5
Joe Wright <jo********@comcast.net> writes:
jo********@techie.com wrote:
I am trying to compile the program hull
http://cm.bell-labs.com/netlib/voronoi/hull.html
This is quite a complicated program that involves several .c files
I get several warnings during compilation and the error:
hullmain.c:40: initializer element is not constant
This is the offending line:
FILE *INFILE, *OUTFILE, *DFILE = stderr, *TFILE;
[...] Probably because we can't find stdio.h where stderr is '#define'ed.


Doubtful. If <stdio.h> weren't included, the compiler would complain
that FILE and stderr are undeclared. (Actually, due to the way
typedefs are handled, it would probably get a parse error.)

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
Thanks Eric, and everyone else who suggested this!
Now the program compiles properly.

"Initialize" DFILE by assigning to it before it is used,
probably very early in main():

FILE *DFILE;
int main(...) {
DFILE = stderr;
...
}


Cheers
Bill

Nov 14 '05 #7

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

Similar topics

3
by: Gary Stephenson | last post by:
I'm getting a clean generate, compile and link from my .pyx script, but when I attempt to run the resultant .exe, I get: "The procedure entry point Py_NoneStruct could not be located in the...
3
by: Christopher M. Lusardi | last post by:
Hello, THE PROBLEM ----------- If I compile parts of my program with CC, and C, using extern "C" as appropriate it compiles without any errors, but it does a segmentation fault when I run the...
13
by: Amadeus W. M. | last post by:
I have a member static const int x defined in class Foo, and I'm passing it by reference, and by value elsewhere (see the code below). Passing it by value works, but by reference it doesn't: it...
3
by: Webdiyer | last post by:
I want to integrate SecurID two-factor authentication system of the RSASecurity.inc into our asp.net application,but I get into trouble when trying to call the API functions of the ACE Agent,I got...
0
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
2
by: ajikoe | last post by:
Hi, I tried to follow the example in swig homepage. I found error which I don't understand. I use bcc32, I already include directory where my python.h exist in bcc32.cfg. /* File : example.c...
23
by: Marco | last post by:
Could anyone please tell me why the program has the following error? I copy the program from http://www.beyondlogic.org/parlcd/parlcd.htm ...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
10
by: Jaco Naude | last post by:
Hi, I am running into a problem where I am trying to import C DLL into a Visual C++ 2008 application. The functions in the C DLL are obviously not name mangled (verified using Dependency...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.