File descriptors and streams and ..

Rich Salz rsalz at bbn.com
Tue Apr 18 10:57:23 AEST 1989


In <207600018 at s.cs.uiuc.edu> carroll at s.cs.uiuc.edu writes:
> why can't you switch stdin by having another variable
>FILE *tmp;
>and doing
>tmp = stdin; stdin = my_file;  do_stuff(); stdin = tmp;

Because |stdin| is not required to be an lvalue.  On many standard i/o
implementations you have this in <stdio.h>:
	#define stdin	&_iob[0]
and that means |stdin| can't appear on the left side of an assignment
statement.  This was mentioned in K&R1 and (I believe) is also allowable
in ANSI and Posix.

(For those who care, on VMS stdin/stdout/stderr are variables; this
makes most lex output uncompileable without massaging.)
	/r$
-- 
Please send comp.sources.unix-related mail to rsalz at uunet.uu.net.



More information about the Comp.lang.c mailing list