sizeof "string"? multi-line macro usage?

ark at alice.UUCP ark at alice.UUCP
Mon Jul 14 10:43:25 AEST 1986


re: is sizeof("...") legal?

> This worked great when
> compiled on Pyramid C, VAX VMS C, and Lattice C on a PC.  Then I ran into the
> Regulus C compiler (Regulus 4.2C) which is truly brain-damaged in many
> respects; as far as I can tell, its sizeof returns a random value when given
> a string.  So is it just Regulus that's screwed up ... ?

If you want your code to work on a particular compiler,
then the language definition doesn't matter if that compiler
doesn't accept it.  Thus, although K&R says:

	A string has type ``array of characters'' ...  (p. 181)

and

	When [sizeof is] applied to an array, the result
	is the total number of bytes in the array.

and thus one should conclude that sizeof("...") is legal,
that doesn't do you a bit of good if your compiler doesn't like it.



More information about the Comp.lang.c mailing list