limitations of casts, pointer and function declarartions...

Geoff Kuenning geoff at desint.UUCP
Sat Nov 3 13:58:27 AEST 1984


In article <6126 at mcvax.UUCP> guido at mcvax.UUCP (Guido van Rossum) writes:

>>	int x;
>>	char *y;
>>/*### [cc] illegal lhs of assignment operator = %%%*/
>>	(char *)x = y;
>
>Sorry, you're thinking Algol-68.  What you need is:
>	*( (char*) &x ) = y;
>

I don't think that's the code that was intended.  The guy wanted to do
the same as

	x = (int) y;

but wanted to put the typecast on the left instead of the right for
readability reasons.  Guido's code gives us the equivalent of this Vax code:

	x &= ~0xFF;
	x |= (int) y & 0xFF;

and other code on other machines, depending on word size and byte ordering.

-- 

	Geoff Kuenning
	First Systems Corporation
	...!ihnp4!trwrb!desint!geoff



More information about the Comp.lang.c mailing list