increment casted void pointer -- ANSI?
Stanley Friesen
sarima at tdatirv.UUCP
Tue Mar 12 03:06:17 AEST 1991
In article <1991Mar8.165300.11692 at zoo.toronto.edu> henry at zoo.toronto.edu (Henry Spencer) writes:
>In article <4142 at rwthinf.UUCP> berg at marvin.e17.physik.tu-muenchen.de (Stephen R. van den Berg) writes:
>> b=*++(char*)p;
>> *--(char*)p=b;
>> *++(char*)p=a;
>There is no way to say "pretend this variable has a different type" in C.
Not true, there *is* a way, Stephen just didn't use it.
To pretend a variable has a different type utter the following magic
incantations:
b = *++ *(char **)&p;
*-- *(char **)&p = b;
*++ *(char **)&p = a;
Now, I consider thsi hideous code, but it *does* allow nearly arbitrary
type punning. [the *effect* is still non-portable]
--
---------------
uunet!tdatirv!sarima (Stanley Friesen)
More information about the Comp.lang.c
mailing list