increment casted void pointer -- ANSI?

Walter Bright bright at nazgul.UUCP
Sat Mar 23 21:34:16 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:
/> *++(char*)p=a;
/>Now, you tell me if this is ANSI or K&R or neither...
/Neither.  The result of a cast is not an lvalue, and ++ and -- apply only
/to lvalues in either K&R C or ANSI C.
/There is no way to say "pretend this variable has a different type" in C.
/Casts are conversions, not "view this bit pattern differently" operators

The usual to do a 'type paint', which is to change the type of an object
without changing the bit pattern, is to:
	*(newtype *)&(object)
It's not perfect, i.e. strict ANSI compilers won't let you do this on an lvalue
and it doesn't work on constants, but it usually gets the job done (a good
compiler will optimize away the redundant *&).



More information about the Comp.lang.c mailing list