home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!spool.mu.edu!agate!usenet.ins.cwru.edu!magnus.acs.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!cbnewse!cbnewsd!att-out!rutgers!concert!rock!taco!csemail.cropsci.ncsu.edu!samodena
- From: samodena@csemail.cropsci.ncsu.edu (S. A. Modena)
- Newsgroups: comp.lang.pascal
- Subject: Re: Pointer problems...
- Message-ID: <1992Nov24.014753.9483@ncsu.edu>
- Date: 24 Nov 92 01:47:53 GMT
- References: <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca> <KIM.92Nov23091623@kim.Software.Mitel.COM> <dmurdoch.301.722547756@mast.queensu.ca>
- Sender: news@ncsu.edu (USENET News System)
- Organization: Crop Science Dept., NCSU, Raleigh, NC 27695-7620
- Lines: 80
-
- In article <dmurdoch.301.722547756@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
- >In article <KIM.92Nov23091623@kim.Software.Mitel.COM> kim@Software.Mitel.COM (Kim Letkeman) writes:
- >>| var
- >>| P1 : ^Byte;
- >>| P2 : ^Byte;
- >>| begin
- >>| new(p1);
- >>| p2:=p1; { Why is this illegal }
- >>
- >>Compiles fine for me.
- >
- >Which compiler are you using? I get compile errors in both TP 6.0 and BP
- >7.0. The problem is that P1 and P2 are being declared to be two different
- >types of pointers, and different types of pointers are generally not
- >assignment compatible.
- >
- >The fact that these two types of pointers are constructed in the same way is
- >the confusing part. This particular feature of Pascal is designed to catch
- >errors like the following:
-
- Though Duncan reply was "correct and legal," allow me to explain it
- differently.
-
- VAR
- P1 : ^BYTE;
- P2 : ^BYTE;
-
- The compiler has to set P1 up on an internal list, not as a TYPE, but
- as a specific OPERATIONAL-type.
-
- Ditto for P2.
-
- Now when the compiler comes to:
-
- P2 := P1;
-
- A search determes that P2 and P1 are NOT together as the same TYPE, but
- each stand as a UNIQUE OPERATION-dependent classification; AND the
- compiler is not trained to compare OPERATION-UNIQUE categorizations;
-
- Now, let change the program just slightly;
-
- TYPE
- PBYTE = ^BYTE;
-
- Notice that I have assign a LABEL to this OPERATION-dependent
- classification;
-
- VAR
- P1 : PBYTE;
- P2 : PBYTE;
- BEGIN
- New( P1 );
- P2 := P1; <==== Both variables SHARE the SAME LABEL and are
- found to be members of the same subset.
-
- Thus the compile checks the statement P2 := P1 by saying: P1 is found
- under label PBYTE and P2 is found under label P1; all is OK!
-
- Previously the compiler tries to check the statement P2 := P1 by saying:
- P1 is a SOME-KIND-OF-AN-OPERATION-TYPE and P2 is is a SOME-KIND-OF-AN-
- OPERATION-TYPE; This compiler only knows how to compare LABELS; therefore,
- ERROR RAISED!
-
-
- See how that works now?
-
- Steve
- ---
- +------------------------------------------------------------------+
- | In person: Steve Modena AB4EL |
- | On phone: (919) 515-5328 |
- | At e-mail: nmodena@unity.ncsu.edu |
- | samodena@csemail.cropsci.ncsu.edu |
- | [ either email address is read each day ] |
- | By snail: Crop Sci Dept, Box 7620, NCSU, Raleigh, NC 27695 |
- +------------------------------------------------------------------+
- Lighten UP! It's just a computer doing that to you. (c)
- OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
-
-