incrementing after a cast

braner at batcomputer.UUCP braner at batcomputer.UUCP
Wed Dec 10 15:04:47 AEST 1986


[]

I tried to be brief and got dumped on...

When I suggested a standard that "things be stored upwards in memory",
I meant inside arrays and as arguments passed to a function (on the stack,
usually).  If things were not stored that way, we wouldn't be talking
about incrementing a pointer as adding sizeof(...) to the address!

In the case where the "things" are of different types, as in the arguments-
on-the-stack case, their position must anyway be adjusted to fit the
alignment requirements of each type.  I gave the example of pushing a byte
on the stack on the 68000: a word (two bytes) is pushed to preserve
the even-ness of the stack pointer.  This could allow some reasonable
way to do "varargs".  It can also cause problems:  adding sizeof(char)
to a pointer used to access the stacked stuff will NOT work right on
the 68000, due to the above-mentioned automatic alignment.  This may
or may not be related to K&R introducing the automatic cast into an int
for calculations (and function calls) involving chars...

(If it still doesn't make any sense to you, Mike, it's YOUR problem :-)

- Moshe Braner



More information about the Comp.lang.c mailing list