Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: nyu notesfiles V1.1 4/1/84; site rna.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!genrad!teddy!panda!talcott!harvard!seismo!cmcl2!rna!kc From: kc@rna.UUCP Newsgroups: net.lang Subject: Re: Comparing pointers in Pascal Message-ID: <6000001@rna.UUCP> Date: Sat, 12-Jan-85 12:52:00 EST Article-I.D.: rna.6000001 Posted: Sat Jan 12 12:52:00 1985 Date-Received: Tue, 15-Jan-85 05:46:50 EST References: <3161@ucla-cs.UUCP> Lines: 42 Nf-ID: #R:ucla-cs:-316100:rna:6000001:000:1854 Nf-From: rna!kc Jan 14 12:52:00 1985 /***** rna:net.lang / ucla-cs!dimare / 2:42 am Jan 11, 1985*/ > I just ran into a problem with pointers in Pascal: I have > two lists of pointers, and I need to find the intersection > of them. Due to the nature of the problem, it's cheaper to > keep these lists ordered. > However, Pascal complains when I try to campare two pointer > variables with operators different than = and <>: > > E 6 - < not allowed on pointers - only allow = and <> > I'm not trying to do arithmetic with pointers, I only need > to order them. I think this restriction is excessive. Is there > a good reason for it? Would Modula-2 behave in the same way? > Is it that Berkely Pascal is a wacko? > Adolfo In Pascal, as in Modula-2, pointers are intended primarily for accessing dynamically allocated data. Thus there aren't any good reasons to compare two pointers; why would you care whether one dynamic datum was stored before or after another in memory. I know, many people do more interesting things with pointers, but the original intent was very restrictive, hence the language design is restrictive. Both languages allow just three pointer operation: dereferencing, equality comparison, and assignment. Equality tests (or inequality) are allowed on pointers because one often wants to know if two pointers are pointing at the same thing. In Modula-2 there is a special pointer type called ADDRESS that is less restrictive than ordinary pointer types. In most versions of M2, ADDRESSES are compatible with an arithmetic type, (usually CARDINAL) thus it would be possible to perform comparisons. Also, in Modula-2 it would be possible to perform type transfers (casts in C terminology) to allow comparisons of pointers. Although these things are possible in M2, they don't come cheap (many keystrokes). Kaare Christian uucp:cmcl2!rna!kc The Rockefeller U.