increment casted void pointer -- ANSI?

Henry Spencer henry at zoo.toronto.edu
Sat Mar 9 02:53:00 AEST 1991


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;
>
>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
(although historically there was some confusion about this, especially
since some conversions sometimes don't actually require changing the bits).

>how do I do it in ANSI then?

Declare a local variable of type `char *', assign the value of `p' to it,
and then do what you want with the variable.

>I always thought this was ANSI code...

What on Earth made you believe that?
-- 
"But this *is* the simplified version   | Henry Spencer @ U of Toronto Zoology
for the general public."     -S. Harris |  henry at zoo.toronto.edu  utzoo!henry



More information about the Comp.lang.c mailing list