Harald van Dijk <> writes:
> On Tue, 08 Apr 2008 19:17:45 +0000, Richard Heathfield wrote:
>> I'm not sure whether FILE's details are /allowed/ to be hidden - or
>> rather, I'm fairly sure they're not. That is, I believe the following
>> program to be strictly conforming:
>>
>> #include <stdio.h>
>>
>> int main(void)
>> {
>> printf("%lu\n", (unsigned long)sizeof(FILE)); return 0;
>> }
>>
>> ...which won't compile if FILE is opaque.
>
> <nit>
>
> That is not a strictly conforming program. The number it outputs is
> unspecified, and I'm sure you didn't mean to suggest otherwise. It must
> be accepted by any conforming hosted implementation, because it's a
> _correct_ program, not a strictly conforming one.
But this is strictly conforming:
#include <stdio.h>
int main(void)
{
printf("%d\n", sizeof(FILE) > 0); return 0;
}
and must print 1.
My point about FILE is that it's a good example of something that's
*used* as an opaque type. A non-portable program theoretically could,
assuming that FILE is a typedef for a structure, mess around with the
members of that structure:
#include <stdio.h>
int main(void)
{
/* NON-PORTABLE: */
printf("stdin->_file = %d\n", stdin->_file);
printf("stdout->_file = %d\n", stdout->_file);
printf("stderr->_file = %d\n", stderr->_file);
return 0;
}
but I've seen remarkably few actual examples of that kind of thing.
--
Keith Thompson (The_Other_Keith) <kst->
Nokia
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
|