Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!uunet!pilchuck!dataio!fnx!nazgul!bright From: bright@nazgul.UUCP (Walter Bright) Newsgroups: comp.lang.c Subject: Re: increment casted void pointer -- ANSI? Message-ID: <288@nazgul.UUCP> Date: 23 Mar 91 11:34:16 GMT Article-I.D.: nazgul.288 References: <4142@rwthinf.UUCP> <1991Mar8.165300.11692@zoo.toronto.edu> Reply-To: bright@nazgul.UUCP (Walter Bright) Organization: Zortech, Seattle Lines: 15 In article <1991Mar8.165300.11692@zoo.toronto.edu> henry@zoo.toronto.edu (Henry Spencer) writes: /In article <4142@rwthinf.UUCP> berg@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 *&).