incrementing after a cast
Garry Wiegand
garry at batcomputer.tn.cornell.edu
Fri Dec 5 09:15:58 AEST 1986
In a recent article kanner at apple.UUCP (Herbert Kanner) wrote:
>...
> L = *((sometype *) chp)++;
>...
>Our problem arises with the allegation that K&R makes this construct
>illegal...
This was some discussion on the net a few months about whether this ought
to be legitimate. The context I would use it in is trying to recycle
"valuable" register variables to point to different things during the life
of a routine. For example, if I happen to know that A and B never overlap
during execution, and that my machine only has 1 available-to-C register,
I might want to do:
...
register char *A;
# define B ((float *)A)
...
and expect both *A++ and *B++ to work and to be in registers for me. If
I know that a pointer and an int take the same space and instructions on
my machine I might also want to get away with:
register char *A;
# define B ((int)A)
...
... *A++; ...
...
... B = 27;
Unfortunately, that's not the way things stand on any compiler I have access
to - your compiler must be exceptionally forgiving.
I think the new spec doesn't disturb the status quo.
garry wiegand (garry%cadif-oak at cu-arpa.cs.cornell.edu)
More information about the Comp.lang.c
mailing list