Path: utzoo!mnetor!uunet!iscuva!carlp From: carlp@iscuva.ISCS.COM (Carl Paukstis) Newsgroups: comp.lang.c Subject: Re: Is &a[NTHINGS] legal Message-ID: <1450@iscuva.ISCS.COM> Date: 3 May 88 23:17:46 GMT References: <12074@tut.cis.ohio-state.edu> <7806@brl-smoke.ARPA> <2637@ttrdc.UUCP> Organization: ISC Systems Corporation, Spokane, WA Lines: 41 In article <2637@ttrdc.UUCP> levy@ttrdc.UUCP (Daniel R. Levy) writes: =In article <7806@brl-smoke.ARPA>, gwyn@brl-smoke.ARPA (Doug Gwyn ) writes: =# In article <12074@tut.cis.ohio-state.edu> lvc@tut.cis.ohio-state.edu (Lawrence V. Cipriani) writes: =# >Is it legal to apply the & (address of) operator to an array =# >element that is non-existent? Given: =# > sometype a[NTHINGS], *p; =# >Should: =# > for (p = a; p < &a[NTHINGS]; p++) /* 1 */ =# >be written as: =# > for (p = a; p <= &a[NTHINGS-1]; p++) /* 2 */ =# > ... =# >Will 1 be guaranteed to work in ANSI-C? =# =# ... =# Every object must have at least one addressable cell beyond it, =# but not necessarily in front of it. I thought that the requirement was, in effect, that there must be at least one valid ADDRESS beyond the composite object. Maybe this is what you're saying, but... =A picky point if you will: would not one expect that &a[NTHINGS] must have at =and beyond it at least as many bytes as the smallest object having the same =alignment requirement as an object having the type of a[0]? Imagine a[] =being laid out in a segment of memory as close to the "top" as possible while =still having &a[NTHINGS] be valid, and you'll see what I mean. The above notion follows from a quick reading of Mr. Gwyn's original followup. It seems, however, that there need not be an addressable OBJECT beyond the array bound, and it is an error to attempt to dereference a[NTHINGS+1]. There must be a valid ADDRESS (or at least simulation of one), so that size calculations will work, mostly, but also so that bound-checking as proposed in the original posting is possible. Maybe I've just added to the confusion, here... -- Carl Paukstis +1 509 927 5600 x5321 |"I met a girl who sang the blues | and asked her for some happy news UUCP: carlp@iscuvc.ISCS.COM | but she just smiled and turned away" ...uunet!iscuva!iscuvc!carlp | - Don MacLean