A cast pointer is NOT an lvalue!? (ANSI C)

Norman Diamond diamond at csl.sony.JUNET
Wed Oct 12 09:35:39 AEST 1988


In article <479 at midgard.mn.org>, dal at midgard.mn.org (Dale Schumacher) writes:
> I used a pointer cast construct like this:
> 
>    value = *((long *) argp)++;

Since you wanted a post-increment, it is trivial to do it properly:

     value = *((long *) argp++);

If you wanted to increment argp by the length of a (long *), then you
have to do:

     value = *(long *) argp;
     argp += (sizeof (long *)) / (sizeof argp);

which cannot give a correct result if sizeof (long *) is not a
multiple of sizeof (int *).  However, despite all the discussions
I've seen about various brain-damaged machines, none had *these*
two sizes unequal.  Anyway, it will work whenever your attempted
original version would work.
-- 
-------------------------------------------------------------------------------
  The above opinions are my own.   |   Norman Diamond
  If they're also your opinions,   |   Sony Computer Science Laboratory, Inc.
  you're infringing my copyright.  |   diamond%csl.sony.jp at relay.cs.net



More information about the Comp.lang.c mailing list