Pointers in C

Phil Pfeiffer <pfeiffer@herve.cs.wisc.edu>
Tue, 5 Jul 88 15:03:21 CDT

          From comp.compilers

Related articles
Pointers in C pfeiffer@herve.cs.wisc.edu (Phil Pfeiffer) (1988-07-05)
Re: Pointers in C louie@trantor.umd.edu (1988-07-06)
Re: Pointers in C mrspock@hubcap.clemson.edu (1988-07-06)
Re: Pointers in C daveb@geac.uucp (1988-07-13)
| List of all articles for this month |
Posted-Date: Tue, 5 Jul 88 15:03:21 CDT
Date: Tue, 5 Jul 88 15:03:21 CDT
From: Phil Pfeiffer <pfeiffer@herve.cs.wisc.edu>

Before other comp.compiler readers are quick to point out that my posting about
C's semantics was not totally accurate:


When I posted that C's semantic model allowed unconstrained use of pointers,
I said this based on my experience with the Unix C compiler, and did not
double-check K&R before posting. My mistake. I received two communiques
today from Bob Larson (blarson%skat.usc.edu@oberon.usc.edu) that I'd like
to pass along (with his permission) before other comp.compiler readers
correct me, as well.


> But C does constrain pointer arithmatic to the bounds of the array.
> (ANSI will allow the address folowing the array to be calculated but
> not referenced.) Most compilers don't enforce this, but it is there
> in K&R ....
>
>K&R 1, page 98:
>"But all bets are off if you do arithmetic or comparisons with pointers
>pointing to different arrays. If you're lucky, you'll get obvious
>nonsense on all machines. If you're unlucky, your code will work on one
>machine but collapse mysteriously on another."
>
>This doesn't seem to be restated in the refernce manual section.
>
>My copy of K&R 2 is elsewhere, but I'm pretty sure the restriction still
>holds. (My info on ANSI C is mostly from comp.lang.c and comp.std.c,
>so is less than perfectly reliable.)


Also, on page 90 of K&R (version 1):


"You should also note the implications in the declaration that a pointer is
constrained to point to a particular kind of object."


I guess this is why formal language specification and compiler validation
were invented.




-- Phil
[From Phil Pfeiffer <pfeiffer@herve.cs.wisc.edu>]
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.