Bug 5634
Summary: | stdio.h dosn't define stderr, stdout, and stdin | ||
---|---|---|---|
Product: | [Retired] Red Hat Linux | Reporter: | joverly |
Component: | gcc | Assignee: | 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: | |
Embargoed: |
Description
joverly
1999-10-06 15:15:25 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; } |