A cast pointer is NOT an lvalue!? (ANSI C)
david wald
wald-david at CS.YALE.EDU
Sat Nov 5 05:21:37 AEST 1988
In article <10034 at socslgw.csl.sony.JUNET> diamond at csl.sony.JUNET (Norman Diamond) writes:
>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)++;
>
>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 *).
How about:
value = *(long *)argp;
argp = (argtype *)((char *)argp + sizeof(long *));
where argtype is the type of *argp?
============================================================================
David Wald wald-david at yale.UUCP
waldave at yalevm.bitnet
============================================================================
More information about the Comp.lang.c
mailing list