type cast in initializer

Joseph S. D. Yao jsdy at hadron.UUCP
Sun Feb 2 02:35:30 AEST 1986


In article <1450 at bbncc5.UUCP> keesan at bbncc5.UUCP (Morris M. Keesan) writes:
>In article <302 at hsi.UUCP> stevens at hsi.UUCP (Richard Stevens) writes:
>>	int	x = 0;
>>	char	*ptr = (char *) &x;
>    In any case, I'm not sure why you'd want to do what your example does,
>since the cast here is a no-op.  

Two reasons are immediately obvious.  The less compelling is that
lint tells you to.  The more compelling is that on some computer
architectures, e.g. one with type-tagged pointers, the cast may
[ NOTE:  n o t  "will", just "may" ] not be a no-op.  Some compilers
will even reject the un-cast initialisation out of hand.

Come to think of it, the 'lint' reason is not less compelling.
Since you are doing something "unnatural" -- pointing to an object
of one type with a pointer of another type -- this falls under the
heading of explicitly having to say, "yes, this is not an error, I
do mean to do exactly what this says."
-- 

	Joe Yao		hadron!jsdy at seismo.{CSS.GOV,ARPA,UUCP}



More information about the Comp.lang.c mailing list