Newsgroups: comp.lang.c
Path: utzoo!henry
From: henry@zoo.toronto.edu (Henry Spencer)
Subject: Re: increment casted void pointer  --  ANSI?
Message-ID: <1991Mar8.165300.11692@zoo.toronto.edu>
Date: Fri, 8 Mar 1991 16:53:00 GMT
References: <4142@rwthinf.UUCP>
Organization: U of Toronto Zoology

In article <4142@rwthinf.UUCP> berg@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@zoo.toronto.edu  utzoo!henry
