Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!border3.nntp.dca.giganews.com!Xl.tags.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!local2.nntp.dca.giganews.com!nntp.earthlink.com!news.earthlink.com.POSTED!not-for-mail NNTP-Posting-Date: Mon, 19 Sep 2011 18:17:44 -0500 Message-ID: <4E77CD96.3419@mindspring.com> Date: Mon, 19 Sep 2011 19:17:42 -0400 From: pete Reply-To: pfiland@mindspring.com Organization: PF X-Mailer: Mozilla 3.04Gold (WinNT; I) MIME-Version: 1.0 Newsgroups: comp.lang.c Subject: Re: Testing if a pointer is valid References: <485d26ed-8e0c-4ad2-92de-ac71961b75dd@17g2000yqv.googlegroups.com> <4e767c92.282513661@text.giganews.com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 51 X-Usenet-Provider: http://www.giganews.com NNTP-Posting-Host: 4.156.228.152 X-Trace: sv3-uQhTfqM0LnKXDTCMTknah6Np4FOV6VmMFBpYYKK4ZepQVVrbT5DJYVKhKyQpkXgiH9dBQ26u8H/co1m!UH0H85IHYXScqHo4q/Em8mbnu5MZzNIKYRWEEAlUXekmJgtA9bpgUfXGsWJKSnOyPwvSo/D2C9oa!0dp5n8N11vM= X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly X-Postfilter: 1.3.40 X-Original-Bytes: 2651 Xref: x330-a1.tempe.blueboxinc.net comp.lang.c:10543 Joe Wright wrote: > > On 9/18/2011 20:32, Keith Thompson wrote: > > cri@tiac.net (Richard Harter) writes: > > [...] > >> Any language in which it is possible > >> for a pointer to be invalid but > >> which provides no way to test for validity is fundamentally flawed. > > > > What existing language has pointers > > and is not "fundamentally flawed"? > > > Indeed. Testing a pointer by simple inspection > can tell you whether it is null or not. > If it is null it is not valid. > If not you simply can't tell. "null" isn't the last word as to whether or not a pointer is valid. "validity" is context dependent. The most invalid pointer value, is an indeterminate pointer value. You can't do anything with an indeterminate pointer value. Next on the list, is a null pointer value. There's nothing wrong with int *a = 0; int *b = a; if (b == a) free(a); Next on the list, is the one past pointer. You can do pointer arithmetic with the one past pointer. int a; int *one_past = &a + 1; if (one_past - 1 == &a) one_past[-1] = 5; And there are also operators, such as greater than (>) which have their own specifications as to what's valid and what isn't. Given: int a; int b; int *one_past = &a + 1; This is valid: if (one_past > &a) ; This isn't valid: if (&b > &a) ; -- pete