misleading statement in bugs.html#known
Geoff Keating
geoffk@geoffk.org
Wed Dec 5 13:52:00 GMT 2001
Per Bothner <per@bothner.com> writes:
> The bugs.html files says 'FILE *yyin = stdin' "will not compile with GNU
> libc (GNU/Linux libc6), because stdin is not a constant. This was done
> deliberately, in order for there to be no limit on the number of open
> FILE objects."
>
> The latter has nothing to do with it. It is easy to make stdin be
> a constant while still having no limit on the number of open FILE
> objects. For example:
>
> extern FILE __stdin;
> @define stdin (&__stdin)
>
> The point is that glibc allows you to *assign* to stdin, so it is
> no longer constant. This is a questionable feature..
Actually, neither of these are the real reason. I believe the
definition of stdin was changed so that user programs didn't need to
know the size of 'FILE'. If a user program writes
printf (&__stdin, ...)
then this works with dynamic linking by creating space in the
executable for '__stdin', resolving the address of __stdin at link
time, and copying at startup time the initial contents of __stdin to
that space (this is done because addresses in applications are not
resolved at run time). If __stdin grows in size in future glibc
versions, the space reserved in old applications will be too small,
and special compatibility code is required. So instead, 'stdin' is
made a variable of type 'FILE *', which is not likely to change in
size in future versions.
--
- Geoffrey Keating <geoffk@geoffk.org> <geoffk@redhat.com>
More information about the Gcc
mailing list