Ancient_Hacker said:
I meant you can use considerable flexibility in what you put after
sizeof, witness:
#include<stdio.h>
main()
{ int a,b,c;
int count = 1;
count = sizeof( 6 );
count = sizeof( a + b );
count = sizeof( (double *) &a );
count = sizeof( sizeof(a) );
count = sizeof( &printf );
count = sizeof( printf("foo" ) );
count = sizeof( 1.234E-4 );
count = sizeof( 3.4 / 5.6 );
count = sizeof( (float
***************************************************) &a );
printf( "%d\n", count );
return 0;
}
Ok, but once again that's not what you actually wrote. What you
actually wrote was:
You see, sizeof can take any expression or type as an argement.
which is not correct. pete's statement was correct. To be precise,
the relevant portion of the grammar is:
unary-expression:
...
sizeof unary-expression
sizeof ( type-name )
This, of course, covers all the cases in your sample program, but it
does not cover a number of cases implied by your original statement,
such as:
sizeof(void)
sizeof main
sizeof obj.bitfield
sizeof exit(0)
/* All of thses are constraint violations. */
Now I'm sure you know all of this, but that's not really the point.
The point is that you seem to expect us all to assume that you know
what you're talking about, and automatically and quietly translate any
incorrect or imprecise statements you might make into something that's
correct and precise. Nobody else here gets that kind of special
treatment (I certainly don't), and neither will you.
If you're such an expert, take the time and effort to make correct
statements in the first place. If you make mistakes, as we all do,
that's ok, but don't get upset when someone corrects them. We're
going to judge what you write by what you write; we're not going to
waste our time trying to guess what you meant.
Finally, I'll make some comments on the program you posted (as I would
do for anyone else):
"int main(void)" is preferred to "main()".
Proper indentation is helpful, even for small programs. (Possibly you
used tabs for indentation and your news software ate them.)
If you wanted to demonstrate the "considerable flexibility in
what you put after sizeof", you might have shown some examples of
"sizeof ( type-name )".