🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: net.lang.pascal
Article #146

Re: Comparing pointers in Pascal

#146
From: DARIN JOHNSON
Date: Fri, 01 Feb 1985 20:36
28 lines
2358 bytes
> 
> 	Say I had a set of records, which I represented as a vector of pointers.
> 	Suppose further that I wanted to test for set membership by comparing
> 	pointers. If I keep the vector sorted by increasing pointer value,
> 	I can do the test in O(lg(N)), using a binary search, but I need
> 	< and > on pointers. If all I have is == and !=, it takes O(N) time.
> 
> 
> It seems to me that the important point here is that Pascal objects to the
> use of the value of a pointer in any attempt to ascertain information about
> where the "pointee" lies in memory.  Pascal does not object to the use of
> an assumption that every unique pointer has a corresponding unique scalar
> value, which may be sorted, compared, etc. just like any integer.  Why not
> use "ord (your_pointer)" for the problem above?  Pascal permits the conversion
> of (unique?)* pointers into (unique?)* integers, but tries to prevent direct
> arithmetic on pointers because this is clearly implementation-dependent.

The whole idea of type checking and other Pascal-gripes is to check for
potential errors.  This doesn't necessarily restrict you.  As shown
above, you can get around the type IF THIS IS WHAT YOU WANTED.  Type
checking is to detect things you didn't want to happen.  With the
pointer case, Pascal checks for < or > comparison because it assumes
that 99% of the time the programmer goofed (admit it, it happens), but
if that is what you really want, use an ord(p) call.  If your system has
strange pointer sizes or doesn't allow ord on pointers, use case variant
records (although you lose portability somewhat).  

    Darin Johnson @ UCSD center for study of centers.
Technical Details
Message-ID: <145@sdcc13.UUCP>
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!cbdkc1!desoto!packard!hoxna!houxm!vax135!cornell!uw-beaver!tektronix!hplabs!sdcrdcf!sdcsvax!sdcc3!sdcc13!ee163acp
References: <3161@ucla-cs.UUCP> <9300010@uiucdcsb.UUCP>

Show Full Headers
Complete Article Headers
Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP
Posting-Version: version B 2.10.2 9/18/84; site sdcc13.UUCP
Path: arc1-ca.pugleaf.net!utzoo!watmath!clyde!cbosgd!cbdkc1!desoto!packard!hoxna!houxm!vax135!cornell!uw-beaver!tektronix!hplabs!sdcrdcf!sdcsvax!sdcc3!sdcc13!ee163acp
From: ee163acp@sdcc13.UUCP (DARIN JOHNSON)
Newsgroups: net.lang.pascal
Subject: Re: Comparing pointers in Pascal
Message-ID: <145@sdcc13.UUCP>
Date: Fri, 1-Feb-85 15:36:52 EST
Article-I.D.: sdcc13.145
Posted: Fri Feb  1 15:36:52 1985
Date-Received: Tue, 5-Feb-85 04:54:03 EST
References: <3161@ucla-cs.UUCP> <9300010@uiucdcsb.UUCP>
Organization: U.C. San Diego, Academic Computer Center
Lines: 28