home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6862 < prev    next >
Encoding:
Internet Message Format  |  1992-11-24  |  3.3 KB

  1. 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
  2. From: samodena@csemail.cropsci.ncsu.edu (S. A. Modena)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Pointer problems...
  5. Message-ID: <1992Nov24.014753.9483@ncsu.edu>
  6. Date: 24 Nov 92 01:47:53 GMT
  7. References: <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca> <KIM.92Nov23091623@kim.Software.Mitel.COM> <dmurdoch.301.722547756@mast.queensu.ca>
  8. Sender: news@ncsu.edu (USENET News System)
  9. Organization: Crop Science Dept., NCSU, Raleigh, NC 27695-7620
  10. Lines: 80
  11.  
  12. In article <dmurdoch.301.722547756@mast.queensu.ca> dmurdoch@mast.queensu.ca (Duncan Murdoch) writes:
  13. >In article <KIM.92Nov23091623@kim.Software.Mitel.COM> kim@Software.Mitel.COM (Kim Letkeman) writes:
  14. >>| var
  15. >>|   P1 : ^Byte;
  16. >>|   P2 : ^Byte;
  17. >>| begin
  18. >>|   new(p1);
  19. >>|   p2:=p1;   { Why is this illegal }
  20. >>
  21. >>Compiles fine for me.
  22. >
  23. >Which compiler are you using?  I get compile errors in both TP 6.0 and BP
  24. >7.0.  The problem is that P1 and P2 are being declared to be two different
  25. >types of pointers, and different types of pointers are generally not 
  26. >assignment compatible.  
  27. >
  28. >The fact that these two types of pointers are constructed in the same way is 
  29. >the confusing part.  This particular feature of Pascal is designed to catch 
  30. >errors like the following:
  31.  
  32. Though Duncan reply was "correct and legal," allow me to explain it
  33. differently.
  34.  
  35. VAR
  36.     P1 : ^BYTE;
  37.         P2 : ^BYTE;
  38.  
  39. The compiler has to set P1 up on an internal list, not as a TYPE, but
  40. as a specific OPERATIONAL-type.
  41.  
  42. Ditto for P2.
  43.  
  44. Now when the compiler comes to:
  45.     
  46.     P2 := P1;
  47.  
  48. A search determes that P2 and P1 are NOT together as the same TYPE, but
  49. each stand as a UNIQUE OPERATION-dependent classification; AND the
  50. compiler is not trained to compare OPERATION-UNIQUE categorizations;
  51.  
  52. Now, let change the program just slightly;
  53.  
  54. TYPE
  55.     PBYTE = ^BYTE;
  56.  
  57. Notice that I have assign a LABEL to this OPERATION-dependent
  58. classification;
  59.  
  60. VAR
  61.     P1 : PBYTE;
  62.     P2 : PBYTE;
  63. BEGIN
  64.     New( P1 );
  65.     P2 := P1;   <==== Both variables SHARE the SAME LABEL and are
  66.             found to be members of the same subset.
  67.  
  68. Thus the compile checks the statement P2 := P1 by saying: P1 is found
  69. under label PBYTE and P2 is found under label P1; all is OK!
  70.  
  71. Previously the compiler tries to check the statement P2 := P1 by saying:
  72. P1 is a SOME-KIND-OF-AN-OPERATION-TYPE and P2 is is a SOME-KIND-OF-AN-
  73. OPERATION-TYPE; This compiler only knows how to compare LABELS; therefore,
  74. ERROR RAISED!
  75.  
  76.  
  77. See how that works now? 
  78.  
  79. Steve
  80. ---
  81. +------------------------------------------------------------------+
  82. |     In person:  Steve Modena     AB4EL                           |
  83. |     On phone:   (919) 515-5328                                   |
  84. |     At e-mail:  nmodena@unity.ncsu.edu                           | 
  85. |                 samodena@csemail.cropsci.ncsu.edu                |
  86. |                 [ either email address is read each day ]        |
  87. |     By snail:   Crop Sci Dept, Box 7620, NCSU, Raleigh, NC 27695 |
  88. +------------------------------------------------------------------+
  89.          Lighten UP!  It's just a computer doing that to you.    (c)
  90. OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
  91.          
  92.