home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / pascal / 6846 < prev    next >
Encoding:
Text File  |  1992-11-23  |  1.6 KB  |  48 lines

  1. Newsgroups: comp.lang.pascal
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sdd.hp.com!swrinde!cs.utexas.edu!torn!news.ccs.queensu.ca!mast.queensu.ca!dmurdoch
  3. From: dmurdoch@mast.queensu.ca (Duncan Murdoch)
  4. Subject: Re: Pointer problems...
  5. Message-ID: <dmurdoch.301.722547756@mast.queensu.ca>
  6. Lines: 36
  7. Sender: news@knot.ccs.queensu.ca (Netnews control)
  8. Organization: Queen's University
  9. References: <1992Nov21.181025.18275@jupiter.sun.csd.unb.ca> <KIM.92Nov23091623@kim.Software.Mitel.COM>
  10. Date: Mon, 23 Nov 1992 19:42:36 GMT
  11.  
  12. In article <KIM.92Nov23091623@kim.Software.Mitel.COM> kim@Software.Mitel.COM (Kim Letkeman) writes:
  13. >| var
  14. >|   P1 : ^Byte;
  15. >|   P2 : ^Byte;
  16. >| begin
  17. >|   new(p1);
  18. >|   p2:=p1;   { Why is this illegal }
  19. >
  20. >Compiles fine for me.
  21.  
  22. Which compiler are you using?  I get compile errors in both TP 6.0 and BP
  23. 7.0.  The problem is that P1 and P2 are being declared to be two different
  24. types of pointers, and different types of pointers are generally not 
  25. assignment compatible.  
  26.  
  27. The fact that these two types of pointers are constructed in the same way is 
  28. the confusing part.  This particular feature of Pascal is designed to catch 
  29. errors like the following:
  30.  
  31.   type
  32.     season = 1..4;
  33.     quarter= 1..4;
  34.   var
  35.     summer : season;
  36.     first : quarter;
  37.   begin
  38.     first := summer;
  39.   end.
  40.  
  41. The assignment here is disallowed, because even though both season and 
  42. quarter are constructed as the same subrange of the integers, they aren't 
  43. the same type.  In the example above, the types are never named, but the 
  44. effect is the same.
  45.  
  46. Duncan Murdoch
  47. dmurdoch@mast.queensu.ca
  48.