[Agreed.]
[Of course it would work.]
[All systems, because FILE is defined to be an object type.]
That's the point. FILE is _not_ incomplete on any system known to
me, in order to allow putc and getc macros to function. Thus you
can write that FILE in = *stdin with impunity on those systems,
and get no errors.
I think most participants in this thread aren't understanding each
other. FILE is not incomplete on any system because *the Standard
says it isn't*! This has nothing to do with the working or not of
putc and getc macros. It's perfectly possible to write macros that
work with incomplete types, for example:
#define FIRST_ELEM(a) (a[0])
where 'a' can be declared with type 'int[]'; or with pointers to
incomplete types, for example:
#define MY_GETC(fp) (fgetc(fp))
where 'fp' is defined with object type 'MY_FILE *' and 'MY_FILE'
is incomplete.
If you then try to pass &in to various
functions, peculiar things are going to happen.
Probably. That's not surprising at all; the value of &in, while
it has the right type (FILE *), was not derived from a call to
'fopen', nor is it equal to 'stdin', 'stdout', 'stderr', or any
other pre-defined 'FILE *' object. So it's basically a garbage
value. Garbage in, garbage out.
I guess a fairly harmless test of this would be:
#include <stdio.h>
/* proving FILE is not incomplete on this system */
int main(void)
{
printf("sizeof(FILE) = %d\n", (int)sizeof(FILE));
return 0;
}
You really could have removed the first and last four lines of that
program, and you still would have had a proof that 'FILE' is not an
incomplete type. The Standard *says* it's not.
-Arthur