increment casted void pointer -- ANSI?

der Mouse mouse at thunder.mcrcim.mcgill.edu
Wed Mar 27 20:10:20 AEST 1991


In article <288 at nazgul.UUCP>, bright at nazgul.UUCP (Walter Bright) writes:
> 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

*except* on an lvalue, I hope you meant.  (Actually, it's something
more like "addressable lvalues" - I don't know the precise wording.)
And you may get garbage when you indirect the resulting pointer.

> and it doesn't work on constants,

They aren't lvalues; you can't apply & to anything but an lvalue.

> but it usually gets the job done

Many not-fully-portable tricks are nevertheless perfectly useful.  Such
a construction is to be discouraged, but not necessarily interdicted
entirely....

					der Mouse

			old: mcgill-vision!mouse
			new: mouse at larry.mcrcim.mcgill.edu



More information about the Comp.lang.c mailing list