Path: utzoo!attcan!uunet!ncrlnk!ncrcae!hubcap!gatech!ncar!umigw!steve From: steve@umigw.MIAMI.EDU (steve emmerson) Newsgroups: comp.lang.c Subject: pointer comparison question Message-ID: <184@umigw.MIAMI.EDU> Date: 9 Nov 88 14:06:08 GMT Reply-To: steve@umigw.miami.edu (steve emmerson) Followup-To: comp.lang.c Distribution: na Organization: University of Miami Lines: 31 (My apologies if this has been covered before---as I'm sure it has :-) I have a question on the validity and desireability of pointer comparisons in the following situation: I have two arrays. The elements of one array are structures and the elements of the other need to be references to those structures. These references could be either pointers or indicies. I wish to perform a consistancy check on the references; in particular, I wish to insure that they are valid (i.e. that the referred-to elements in do, in fact, exist). If indicies are used, I can simply perform range checking. If pointers are used, however, can I verify the references? My fear is that I cannot because the relational comparison of pointers is guaranteed to be valid only for pointers into the same array, and, in this particular situation, that is exactly what I'm trying to determine. Put succinctly, is the following expression true: TestPtr < StartPtr || TestPtr > StopPtr if, and only if, "TestPtr" points someplace outside the "StartPtr" to "StopPtr" range. Must I use indicies and accept their potentially slower performance? Thank you for your advice. -- Steve Emmerson Inet: steve@umigw.miami.edu [128.116.10.1] SPAN: miami::emmerson (host 3074::) emmerson%miami.span@star.stanford.edu UUCP: ...!ncar!umigw!steve emmerson%miami.span@vlsi.jpl.nasa.gov "Computers are like God in the Old Testament: lots of rules and no mercy"