This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: FILE *bla=stderr;




On Wed, 1 Jul 1998, Felix von Leitner wrote:

> The above line gives me the
> 
>   1.c:3: initializer element is not constant
> 
> error with egcs under Linux/AXP but it works with egcs under Linux/SPARC
> and Linux/Intel.  What's up?

Check your language reference manual before bothering a compiler bug
mailing list.

In C, initializers of static objects (this includes objects declared
at file scope, and objects declared in a block scope with the ``static''
storage class specifier) must be constant expressions.

Nowhere in the C language standard is it required that stdin, stdout
and stderr must be constant expressions. They are simply expressions
of type FILE *, not necessarily constant. 

In some environments they may indeed be constant expressions, so

	static FILE *foo = stderr;

will work by sheer luck. For example, the stdio.h header may contain
something like

	#define stdin (&__stdin_object)

Thus in this case, stdin expands to an address constant. But what
if the header contains something like

	extern FILE *stdin;

Then stdin is no longer a constant expression, since it refers
to a pointer value.

Hope this clears things up.




Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]