Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cornell!uw-beaver!apollo!mrst!sdti!turner From: turner@sdti.SDTI.COM (Prescott K. Turner) Newsgroups: comp.std.c Subject: Re: Testing Equal Pointers (was: detecting invalid pointers) Message-ID: <377@sdti.SDTI.COM> Date: 28 Mar 89 14:14:00 GMT References: <1989Mar21.085704.15894@ateng.ateng.com> <16039@cup.portal.com> <375@sdti.SDTI.COM> <9930@smoke.BRL.MIL> Reply-To: turner@sdti.UUCP (0006-Prescott K. Turner, Jr.) Organization: Software Development Technologies, Sudbury MA Lines: 33 In article <9930@smoke.BRL.MIL> gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) writes: >That's all wrong. Pointers to the same object compare equal ... Yes, I was off base in my earlier article. But doesn't the standard permit odd behavior in a case like the following: char a[LIMIT]; char b[LIMIT]; ... if (a+LIMIT == b) ... It appears that a+LIMIT may compare equal to b, in which case 3.3.9 says they point to the same object (b[0]) -- this is what one would expect if the hardware had a simple address space and the allocation happened a certain way. But doesn't the standard permit the behavior which happens with large model compilers for MS-DOS, in which they point to the same object and compare not equal? I guess you're implying that the MS-DOS behavior is covered by saying that a+LIMIT does not point to an object. >(Except that certain operations not permitted of conforming applications >might produce pointers that accidentally refer to the same location; but >since that would be totally erroneous code, you shouldn't worry about it.) The discussion in comp.lang.c arose from a question of how to detect erroneous code, i.e. how to verify that a pointer argument points into a particular array rather than contains garbage. Erroneous code is definitely a concern. It seems that the solution proposed (by Karl Heuer I think) which compares the argument for equality against every element of the array would do the job (inefficiently). If the pointer argument "accidentally" pointed into the array, it might or might not be caught. But any pointer which passes the test does point into the array. -- Prescott K. Turner, Jr. Software Development Technologies, Inc. P.O. Box 366, Sudbury, MA 01776 USA (508) 443-5779 UUCP: ...{harvard,mit-eddie}!sdti!turner Internet: turner@sdti.sdti.com