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