Note: This is a beta release of Red Hat Bugzilla 5.0. The data contained within is a snapshot of the live data so any changes you make will not be reflected in the production Bugzilla. Also email is disabled so feel free to test any aspect of the site that you want. File any problems you find or give feedback here.

Bug 3023

Summary: EGCS / GCC bug
Product: [Retired] Red Hat Linux Reporter: kumarsri
Component: egcsAssignee: David Lawrence <dkl>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0CC: kumarsri
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-05-25 13:57:03 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description kumarsri 1999-05-25 02:34:48 UTC
This looks like a EGCS bug to me:

#include "stdio.h"
FILE *prerror = stderr;
main() {

Put the above lines in a.c and type
gcc -c a.c

Gives error - initializer is not a constant

This used to work with Redhat 5.2 and it also works with
SCO Unix, Solaris, IRIX, AIX etc.

Comment 1 Bill Nottingham 1999-05-25 13:57:59 UTC
It's not an egcs bug. It's part of glibc 2.1;
stdin/stdout/stderr are *NOT* constants, so you
can't do initialization like that. Initialize the
filehandle when you use it to stderr if you like...

From the GLIBC FAQ:

I get compiler messages "Initializer element not constant" with
stdin/stdout/stderr. Why?

Constructs like:
    static FILE *InPtr = stdin;
lead to this message. This is correct behaviour with glibc since stdin
is not a constant expression. Please note that a
strict reading of ISO C does not allow above constructs.

One of the advantages of this is that you can assign to stdin, stdout,
and stderr just like any other global variable
(e.g. `stdout = my_stream;'), which can be very useful with custom
streams that you can write with libio (but
beware this is not necessarily portable). The reason to implement it
this way were versioning problems with the
size of the FILE structure.

To fix those programs you've got to initialize the variable at run
time. This can be done, e.g. in main, like:

static FILE *InPtr; int main(void) { InPtr = stdin; }

or by constructors (beware this is gcc specific):

static FILE *InPtr;
static void inPtr_construct (void) __attribute__((constructor));
static void inPtr_construct (void) { InPtr = stdin; }