type cast in initializer

art at acc.arpa art at acc.arpa
Sat Feb 1 10:08:54 AEST 1986


 
> 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

The posting did not indicate whether the variables are static or auto.

The initializer should be legal if x is static, but not neccesarily if
x is declared as an auto.  If x is auto, the compiler could place it in
a register whose address cannot be taken.

The compiler should be smart enough to notice the address operator and
disallow register allocation.  K&R only states that variables declared
register cannot have their address taken.  Anyone know what ANSI says?

------



More information about the Comp.lang.c mailing list