Bug 5634 - stdio.h dosn't define stderr, stdout, and stdin
Summary: stdio.h dosn't define stderr, stdout, and stdin
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 6.0
Hardware: All
OS: Linux
Target Milestone: ---
Assignee: David Lawrence
QA Contact:
Depends On:
TreeView+ depends on / blocked
Reported: 1999-10-06 15:15 UTC by joverly
Modified: 2008-05-01 15:37 UTC (History)
0 users

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Last Closed: 1999-10-06 15:36:52 UTC

Attachments (Terms of Use)

Description joverly 1999-10-06 15:15:25 UTC
In /usr/include (for stderr)
In Redhat 5.2 we have:

extern FILE *stdin, *stdout, *stderr; /* TODO */
#define stdout _IO_stdout

However in Redhat 6.0

extern FILE *stderr;            /* Standard error output
stream.  */

This is causing a problem for the code fragment:

FILE *dsErrOutput_p = stderr;

This works on other platforms as stderr is defined.
Checking with the ANSI standards thsi should be OK.
Does this repesent a change in how IO is handled in
this and future versions of Redhat or is this just
an oversight? We are working on a large software
package and are trying to port our linux versions to
Redhat 6.0 (and higher). Currently our software works
fine on Redhat 5.2.

Jim Overly
Harvard-Smithsonian Center for Astrophysics

Comment 1 Bill Nottingham 1999-10-06 15:36:59 UTC
You cannot statically initialize something as std(err|out|in);
this is a change with glibc-2.1.

From the glibc FAQ:

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

{RM,AJ} 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; }

Note You need to log in before you can comment on or make changes to this bug.