type cast in initializer

Chris Torek chris at umcp-cs.UUCP
Sun Feb 2 12:26:04 AEST 1986


In article <2124 at brl-tgr.ARPA> art at acc.arpa writes:
> The initializer [for
>	int x = 0; char *ptr = (char *) &x;
> ] should be legal if x is static, but not necessarily 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 can only do this if (1) it can take the address of a
register (a la Pyramid) or (2) it has determined that nowhere is
the address actually taken.  The compiler MUST NOT make `&var'
illegal when `var' was not declared `register'.  Another way to
look at this is that `register' is not really a `hint to the
compiler' about using a machine register, but rather a `promise to
the compiler' that the programmer will not take the address of the
variable.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 1415)
UUCP:	seismo!umcp-cs!chris
CSNet:	chris at umcp-cs		ARPA:	chris at mimsy.umd.edu



More information about the Comp.lang.c mailing list