Out of range pointers

will summers will.summers at p6.f18.n114.z1.fidonet.org
Thu Sep 22 13:54:59 AEST 1988


In message  <33547 at XAIT.XEROX.COM> g-rh at XAIT.XEROX.COM (Richard Harter)
writes:
 > >>In C a pointer is a fairly anonymous object.  What you are saying is
 > >>that it is a potential error to add or subtract an integer from a
 > >>pointer if the result is out of range.  Very well, but what is that
 > >>range?
 >
 > >The members of the array that the pointer points into, plus the special
 > >case of just above the end of the array.

This got me thinking about a subtle dpANS wording difference:

    struct _whatever *pstruct;

    pstruct = (struct _whatever *) malloc (n * sizeof(struct _whatever));

        is pstruct[n-1] or pstruct+(n-1) -guaranteed- to be allowed on
        -all- dpANS conformant installations?


        The dpANS (Jan '88) states that malloc() returns space for an -object-
        of size (n * sizeof(struct _whatever)) whereas

            calloc(n, sizeof(struct _whatever))

        allocates space for an -array- of 'n' objects each of whose size
        is sizeof(struct _whatever).


        I guess it comes down to this: does dpANS -guarantee- an object is
        divisable into sub-objects following Chris Torek's "locally
        flat" paradigm, and that pointers produced by arithmetic on 
        pointers to the sub-objects will be valid.

        Simply stated, does dpANS wording imply any difference between

            calloc (n, size) and  malloc (n*size) ?


    \/\/ill


--  
St. Joseph's Hospital/Medical Center - Usenet <=> FidoNet Gateway
Uucp: ...{gatech,ames,rutgers}!ncar!noao!asuvax!stjhmc!18.6!will.summers



More information about the Comp.lang.c mailing list