Bug 5634 - stdio.h dosn't define stderr, stdout, and stdin
stdio.h dosn't define stderr, stdout, and stdin
Status: CLOSED WONTFIX
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
6.0
All Linux
medium Severity medium
: ---
: ---
Assigned To: David Lawrence
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 1999-10-06 11:15 EDT by joverly
Modified: 2008-05-01 11:37 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 1999-10-06 11:36:52 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description joverly 1999-10-06 11:15:25 EDT
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 11:36:59 EDT
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.