The C Standard on segmented machines

19 Jan 86 21:37:00 GMT

          From comp.compilers

Related articles
The C Standard on segmented machines compilers@ima.UUCP (1986-01-19)
| List of all articles for this month |

From: compilers@ima.UUCP
Newsgroups: mod.compilers
Date: 19 Jan 86 21:37:00 GMT
Article-I.D.: ima.136300063
Posted: Sun Jan 19 16:37:00 1986

[from lr at IHNP4/SFBC (Larry Rosler)]

I don't claim to be definitive, and I'm certainly not dmr, but
I'll try to present the X3J11 position on pointers as best I can.

First of all, function pointers and data pointers are conceptually
distinct. No operations except assignment and invocation are
permitted on function pointers; even casting to or from data
pointers are ruled out (but are described as common extensions).
So the rest of the discussion deals only with data pointers.

Data pointers may be added to (or subtracted from or incremented
or decremented), provided the pointer points into an array both
before and after the operation. (A special case is allowed for
pointing one past the last element of an array, to support
coding (like that in K&R) that uses comparison with a[N] to
locate the end of array a of size N. This implies that in a
segmented architecture at least one location after an array
must be addressable.)

In order to support pointer arithmetic, the number of bytes in
an array is restricted to a number that can be stored in an
unsigned integer of size defined by the implementation: unsigned
short or unsigned long. For portability, this type (which is
also the type of the sizeof operator) is defined as size_t in
various standard header files. Presumably, this corresponds
to the size of an address segment. The type size_t is used
instead of int or unsigned int for all functions that require
array-size arguments (such as malloc) or return array-size
values (such as strlen).

The difference between two pointers is defined only if the
pointers point into (or just past) the same array. The
type of the difference, defined as ptrdiff_t, is the signed
version of size_t. Arithmetic overflow can occur if the
pointers point into different halves of a maximally-sized
array; this can be detected by a relational comparison of
the two pointers (which treats the pointers as unsigned).

To summarize, each address segment is treated as a small
linear space, objects may not cross segment boundaries, and
operations involving pointers to different segments are prohibited.

I hope all this is comprehensible and correct. Our member
from Intel has certainly bought into it. Comments and criticism
are welcomed.

[Please send your comments to Larry or to net.lang.c -- I would like to
wrap up this discussion in mod.compilers. I do appreciate Larry's report
on the C standard committee's thoughts on segments. -John]

Larry Rosler
Editor, X3J11

Post a followup to this message

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