The Dangers of sizeof

Maarten Litmaath maart at cs.vu.nl
Tue Apr 11 04:17:08 AEST 1989


penneyj at servio.UUCP (D. Jason Penney) writes:
\...
\I must disagree!  There is only ONE form of sizeof -- the operator form,
\which takes an arbitrary (unevaluated) expression as its argument.

K&R seem to disagree.

\...  Trick question:  what is the value of:
\
\sizeof (char) - 1
\
\Answer:  1 -- the (char) is a cast, which is of higher precedence than
\sizeof, [...]

sizeof and casts have equal precedence.

	% cat c.c
	main()
	{
		printf("%d\n", sizeof(char) - 1);
	}
	% a.out
	0
	%

People, please CHECK things before posting.
-- 
 "If it isn't aesthetically pleasing, |Maarten Litmaath @ VU Amsterdam:
  it's probably wrong." (jim at bilpin). |maart at cs.vu.nl, mcvax!botter!maart



More information about the Comp.lang.c mailing list