Bug 5634

Summary: stdio.h dosn't define stderr, stdout, and stdin
Product: [Retired] Red Hat Linux Reporter: joverly
Component: gccAssignee: David Lawrence <dkl>
Status: CLOSED WONTFIX QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 6.0   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 1999-10-06 15:36:52 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 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; }