Path: utzoo!attcan!uunet!husc6!bloom-beacon!tut.cis.ohio-state.edu!cs.utexas.edu!sdcrdcf!ism780c!haddock!ima!compilers-sender
From: pfeiffer@herve.cs.wisc.edu (Phil Pfeiffer)
Newsgroups: comp.compilers
Subject: Pointers in C
Message-ID: <1262@ima.ISC.COM>
Date: 5 Jul 88 20:03:21 GMT
Sender: compilers-sender@ima.ISC.COM
Reply-To: Phil Pfeiffer 
Lines: 43
Approved: compilers@ima.UUCP
Posted-Date: Tue, 5 Jul 88 15:03:21 CDT

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 ]
--
Send compilers articles to ima!compilers or, in a pinch, to Levine@YALE.EDU
Plausible paths are { ihnp4 | decvax | cbosgd | harvard | yale | bbn}!ima
Please send responses to the originator of the message -- I cannot forward
mail accidentally sent back to compilers.  Meta-mail to ima!compilers-request