Path: utzoo!attcan!uunet!husc6!mailrus!ncar!noao!asuvax!stjhmc!p6.f18.n114.z1.fidonet.org!will.summers From: will.summers@p6.f18.n114.z1.fidonet.org (will summers) Newsgroups: comp.lang.c Subject: Re: Out of range pointers Message-ID: <706.2339B3DF@stjhmc.fidonet.org> Date: 22 Sep 88 03:54:59 GMT Sender: ufgate@stjhmc.fidonet.org (newsout1.24) Organization: FidoNet node 1:114/18.6 - Iasd Eng Bbs, Phoenix Az Lines: 45 In message <33547@XAIT.XEROX.COM> g-rh@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