incrementing after a cast

braner braner at batcomputer.tn.cornell.edu
Sat Dec 6 15:34:13 AEST 1986


[]

If  ((sometype *)pointer)++ is not legal, then the law should be changed!
(since the pointer-type cast is legal, why can't you use the resulting
pointer like any pointer of sometype?)

BUT, if you cast it back, as in varargs with args of various types,
then some machines supposedly give you problems.  But the implementations
should avoid problems by agreeing that:

	consecutive things are stored upwards in memory,

	incrementing a pointer points to the next memory slot,

	casting to a pointer to a type with stricter alignment
	will be rounded UP to fit.  (This has to be done anyway
	when figuring out how to store the stuff.  For example,
	if you push a byte on the 68000 stack a whole word is used.)

As for recycling registers, using the same register for different
types in the same function:  I think that would be very valuable.
How about allowing something like this:

	register union {int i; long j;} x;

If your machine makes it impossible, the compiler can separate them
into separate registers if available, or (as is anyway the case with
register variables) make it non-register.  So no harm done!  To get
the best results, on some machines you would be advised NOT to unionize
int/longs and pointers.

- Moshe Braner



More information about the Comp.lang.c mailing list