home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / pascal / 4630 < prev    next >
Encoding:
Internet Message Format  |  1992-07-30  |  2.9 KB

  1. Path: sparky!uunet!cs.utexas.edu!ut-emx!slcs.slb.com!aa.cad.slb.com!wilson
  2. From: wilson@mailhost.aa.cad.slb.com (David Wilson)
  3. Newsgroups: comp.lang.pascal
  4. Subject: Re: Is this legal - why/why not?
  5. Message-ID: <1992Jul30.202901.2286@mailhost.aa.cad.slb.com>
  6. Date: 30 Jul 92 20:29:01 GMT
  7. References: <1992Jul29.072408.23090@monu6.cc.monash.edu.au> <1992Jul29.201359.4297@nntpd.lkg.dec.com> <1992Jul30.182727.9048@aero.org>
  8. Sender: usenet@mailhost.aa.cad.slb.com (Usenet Administrator)
  9. Organization: Schlumberger CAD/CAM; Ann Arbor, Michigan (USA)
  10. Lines: 52
  11.  
  12. In article <1992Jul30.182727.9048@aero.org> jordan@aero.org (Larry M. Jordan) writes:
  13. >In article <1992Jul29.201359.4297@nntpd.lkg.dec.com> reagan@hiyall.enet.dec.com (John R. Reagan) writes:
  14. >[stuff deleted]
  15. >>
  16. >>There must be bugs in the compilers you use.  There is nothing
  17. >>wrong with redefining predeclared identifiers.  They aren't special
  18. >>in this regard.  You just can't use the same identifier for two
  19. >>things in the same scope.  For example,
  20. >>
  21. >>type foo = integer;
  22. >>     integer = 1..10;
  23. >>
  24. >>is illegal since integer was used for 2 things in the same scope.
  25. >>
  26. >
  27. >Looks legal to me.  Works fine on Sun Pascal.  The first integer is
  28. >from an 'enclosing' scope.  The second integer 'masks' the integer from
  29. >the enclosing scope.  The two integer's are used in the same block, 
  30. >but each has a different scope!  According to Ghezzi and Jazayeri,
  31. >"Programming Language Concepts":
  32. >
  33. >  The scope of a variable is the range of program instructions over
  34. >  which the variable is known.
  35. >
  36. >(This definition applies to types and constants as well).
  37. >
  38. >The above example does not violate the scope rule.
  39.  
  40. First, what constitutes the "scope" of an identifier depends on the language...
  41.  
  42. Mr. Reagan is correct according to the Pascal Standard.  MANY compilers
  43. fail to diagnose violations, as the simplest and most obvious implementations
  44. of scope rules aren't up to it.  I won't bother quoting the Standard (see
  45. section 6.2.2 and especially 6.2.2.5 if you have a copy), but the gist of it
  46. is that the second type declaration "integer = 1..10;" is the defining point
  47. for the 'inner' "integer", and serves to remove the entire block from the
  48. scope of the 'outer' "integer" which "foo = integer" is apparently trying
  49. to refer to.  The "foo" declaration is then attempting to refer to the type
  50. before it has been declared (and since it isn't the target type of a pointer
  51. that isn't legal).
  52.  
  53. As far as quoting Ghezzi and Jazayeri, different languages differ on this
  54. fine point when they define their respective scope rules.  The Pascal
  55. Standard has opted for clarity of the written code at the expense of 
  56. implementation convenience.  Other language designers have resolved the
  57. tradeoffs differently.
  58.  
  59. I haven't tried this case in Turbo Pascal, but Turbo Pascal and Standard
  60. Pascal are distinct languages anyway.  If Sun's Pascal purports to conform
  61. to the Standard, then Sun has an error.  Borland makes no such claim.
  62.  
  63. Dave Wilson
  64.