type cast in initializer

Morris M. Keesan keesan at bbncc5.UUCP
Sat Feb 1 06:18:30 AEST 1986


In article <302 at hsi.UUCP> stevens at hsi.UUCP (Richard Stevens) writes:
>I've found the two lines
>
>	int	x = 0;
>	char	*ptr = (char *) &x;
>
>acceptable to every C compiler I've used, until running into the
>Whitesmith's C compiler.  They refuse to accept the type coercion "(char *)"
>on the second initialization.  As I read K&R this should be acceptable
>through the rules
>
>	initializer:
>		= expression			(Sec. 8.6)
>
>	expression:
>		( type-name ) expression	(Sec. 7.2)
>
>I talked to Whitesmiths about this and they are firm that their
>interpretation of the "standard" is that a type coercion following the
>equals sign is not allowed and they don't plan to change their compiler.

    My interpretation agrees with yours.  Whitesmith are going by section 15,
which enumerates the operators which are allowed in a constant expression,
type-casting not being one of them.  They are missing the additional information
in paragraph 2 of 8.6, which increases the sorts of expression allowed, in
particular allowing automatic variables to be initialized by "arbitrary
expressions involving constants, and previously declared variables and
functions."  

    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.  
-- 
Morris M. Keesan
keesan at bbn-unix.ARPA
{decvax,ihnp4,etc.}!bbncca!keesan



More information about the Comp.lang.c mailing list