Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!ut-ngp!infotel!pollux!bobkat!m5d From: m5d@bobkat.UUCP (Mike McNally ) Newsgroups: comp.lang.c Subject: Re: incrementing after a cast Message-ID: <264@bobkat.UUCP> Date: Mon, 8-Dec-86 16:16:48 EST Article-I.D.: bobkat.264 Posted: Mon Dec 8 16:16:48 1986 Date-Received: Tue, 9-Dec-86 10:59:33 EST References: <349@apple.UUCP> <7376@utzoo.UUCP> <1746@batcomputer.tn.cornell.edu> Reply-To: m5d@bobkat.UUCP (Mr Mike McNally) Organization: Digital Lynx; Dallas TX Lines: 63 Keywords: cast, increment, postincrement In article <1746@batcomputer.tn.cornell.edu> braner@batcomputer.UUCP (braner) writes: >[] > >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?) > You can use the pointer like any other pointer *value*. However, as with any construction resulting in an rvalue, the result of a cast cannot be autoincremented; it has no address. As many have pointed out in this group over the past couple of months, on many machines the casting of one pointer type to another requires that the value be modified in some way. >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, What?? What if the "things" are of different types, and the architecture of the machine favors storage of different types in different segments? What other high-level language guarantees that separately-declared objects are stored consecutively? (I *know* that dozens of people know of dozens of languages for which such assumptions are valid; I don't want to hear about it.) > incrementing a pointer points to the next memory slot, What is a memory slot? In the language I use, C, when a pointer is incremented, it is incremented; afterwards it points to whatever it points to. The amount by which the pointer is incremented is equal to the size of the type pointed to. I guess I must be confused. > 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.) > Rounded UP? Why not down? Then, if I cast a pointer-to-char into a pointer-to-long, the long will contain the char. Actually, I don't think any rounding should be done. The semantics would be too machine- dependent to be of any use in a program. What would it mean anyway? This is too bizarre for me. > [stuff about register variables] >- Moshe Braner I think that further suggestions along the lines of "let's change the language so I can do something disallowed for good reason in the existing language" should be directed to the ANSI committee, where they hopefully will be directed to the ANSI wastebasket. -- **** **** **** At Digital Lynx, we're almost in Garland, but not quite **** **** **** Mike McNally Digital Lynx Inc. Software (not hardware) Person Dallas TX 75243 uucp: ...convex!ctvax!bobkat!m5 (214) 238-7474