P. 1
Draft ANSI C Rationale

Draft ANSI C Rationale

|Views: 5,314|Likes:
Published by inExcelsisDeo
Rationale for Draft Proposed National Standard for Information Systems - Programming Language C (ANSI X3J11/88-151) (Nov 18, 1988)
Rationale for Draft Proposed National Standard for Information Systems - Programming Language C (ANSI X3J11/88-151) (Nov 18, 1988)

More info:

Published by: inExcelsisDeo on Jun 11, 2009
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF or read online from Scribd
See more
See less




As with the sizeof operator, implementations have taken different approaches in
defining a type for the difference between two pointers (see§ It is important



Section 3. LANGUAGE

that this type be signed, in order to obtain proper algebraic ordering when dealing
with pointers within the same array. However, the magnitude of a pointer difference
can be as large as the size of the largest object that can be declared. (And since that
is an unsigned type, the difference between two pointers may cause an overflow.)
The type of pointer minus pointer is defined to be int in K&R. The Stan-
dard defines the result of this operation to be a signed integer, the size of which
is implementation-defined. The type is published as ptrdiff t, in the standard
header . Old code recompiled by a conforming compiler may no longer
work if the implementation defines the result of such an operation to be a type other
than int and if the program depended on the result to be of type int. This behavior
was considered by the Committee to be correctable. Overflow was considered not
to break old code since it was undefined by K&R. Mismatch of types between ac-
tual and formal argument declarations is correctable by including a properly defined
function prototype in the scope of the function invocation.
An important endorsement of widespread practice is the requirement that a
pointer can always be incremented to just past the end of an array, with no fear of
overflow or wraparound:


/* ... */
for (p = &array[0]; p < &array[SPAN]; p++)

This stipulation merely requires that every object be followed by one byte whose
address is representable. That byte can be the first byte of the next object declared
for all but the last object located in a contiguous segment of memory. (In the exam-
ple, the address &array[SPAN] must address a byte following the highest element
of array.) Since the pointer expression p+1 need not (and should not) be derefer-
enced, it is unnecessary to leave room for a complete object of size sizeof(*p).
In the case of p-1, on the other hand, an entire object would have to be allocated
prior to the array of objects that p traverses, so decrement loops that run off the
bottom of an array may fail. This restriction allows segmented architectures, for
instance, to place objects at the start of a range of addressable memory.

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->