Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!rochester!cornell!batcomputer!braner From: braner@batcomputer.tn.cornell.edu (braner) Newsgroups: comp.lang.c Subject: Re: incrementing after a cast Message-ID: <1746@batcomputer.tn.cornell.edu> Date: Sat, 6-Dec-86 00:34:13 EST Article-I.D.: batcompu.1746 Posted: Sat Dec 6 00:34:13 1986 Date-Received: Sun, 7-Dec-86 03:21:33 EST References: <349@apple.UUCP> <7376@utzoo.UUCP> Reply-To: braner@batcomputer.UUCP (braner) Organization: Theory Center, Cornell University, Ithaca NY Lines: 32 Keywords: cast, increment, postincrement [] 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