|Pointers in C firstname.lastname@example.org (Phil Pfeiffer) (1988-07-05)|
|Re: Pointers in C email@example.com (1988-07-06)|
|Re: Pointers in C firstname.lastname@example.org (1988-07-06)|
|Re: Pointers in C email@example.com (1988-07-13)|
|From:||firstname.lastname@example.org (Steve Benz)|
|Date:||6 Jul 88 14:36:25 GMT|
|Organization:||Clemson University, Clemson, SC|
From article <1262@ima.ISC.COM>, by email@example.com (Phil Pfeiffer):
> ...my posting about C's semantics was not totally accurate...
>>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."
To combine this with what was said before: An optimizer can assume
that once a pointer, 'p', is assigned to an address within an array, 'a',
'p' will stay within the bounds of 'a' until assigned to an address
within some other array or in the heap space.
While this assumption is valid (according to the book,) it is also true
that the optimized code may behave differently than unoptimized code,
but only for programs that are not in the domain of valid K&R C programs.
Nevertheless, I can think of a rather large set of programs that
aren't "valid K&R C programs": All those programs that use varargs.
(At least by the definitions of varargs that I've seen.)
> 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 think a C compiler would be very hard pressed to guarantee this sort
of thing, with the cast operation lurking about. The only way to absolutely
guarantee this is to do some unpleasantly complicated typechecking on
every object in memory.
Insofar as mainstream C compilers go, I think you have to accept Phil's
original assertion about pointer operations -- at least within the heap
space. If you can circumvent the varargs problem, you might be able to
get by with the K&R definition in the stack space.
- Steve Benz
Return to the
Search the comp.compilers archives again.