Path: utzoo!mnetor!uunet!tektronix!reed!douglas From: douglas@reed.UUCP (P Douglas Reeder) Newsgroups: comp.lang.pascal Subject: Re: Scope question Message-ID: <8601@reed.UUCP> Date: 31 Mar 88 20:21:44 GMT References: <718@virginia.acc.virginia.edu> Reply-To: douglas@reed.UUCP (P Douglas Reeder) Organization: Reed College, Portland OR Lines: 49 In article <718@virginia.acc.virginia.edu> scl@virginia.acc.virginia.edu (Steve Losen) writes: >The following pascal program compiles and outputs "10" with the Berkeley >pascal compiler "pc". > >program test(output); > const c = 10; > >procedure junk; > const c = c; { Shouldn't this be an error ? } >[rest of program deleted] > >As far as I can tell, then, the pascal fragment > >const c = c; > >should not be allowed even if c is a constant defined in an enclosing >block. Is my interpretation of the pascal standard correct? Since I'm >writing a pascal compiler, I need to have this issue cleared up. > >-- >Steve Losen scl@virginia.edu >University of Virginia Academic Computing Center In the line const c = c; the reference to c on the right refers to the previously defined constant c and the reference on the left refers to the newly defined constant c. In procedure junk, before this statement (that is, in previous constant declarations), c refererred to the first c. After, c refers to the local c. In some sense, the right side of the statement is compiled before the left hand side. The following code does exactly the same thing, using slightly different names: program test(output); const c1 = 10; procedure junk; const c2 = c1; [rest of program ] The same thing happens with your second example [not shown]. My book does not make clear if this is ISO standard. Either way, its meaning is unambiguous. -- Doug Reeder USENET: ...!tektronix!reed!douglas 10 Cyclopedia Square from BITNET: douglas@reed.UUCP Terminus City from ARPA: !tektronix!reed!douglas@Berkley Terminus,The Foundation Box 502 Reed College,Portland,OR 97202