Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!ucbvax!decwrl!sun!aeras!elxsi!beatnix!corbett From: corbett@beatnix.UUCP (Bob Corbett) Newsgroups: comp.lang.pascal Subject: Re: An ISO Pascal question... Message-ID: <2546@elxsi.UUCP> Date: 15 Mar 89 22:04:36 GMT References: <18654@adm.BRL.MIL> <2824@kalliope.rice.edu> <1195@ruuinf.UUCP> Sender: news@elxsi.UUCP Reply-To: uunet!elxsi!corbett (Bob Corbett) Organization: ELXSI Super Computers, San Jose Lines: 73 In article <1195@ruuinf.UUCP> piet@ruuinf (Piet van Oostrum) writes: >In article <2824@kalliope.rice.edu>, mootaz@titan (Elmootazbellah Nabil Elnozahy) writes: > `Given the following piece of code, can anybody familiar with the ISO > `standard tell me if it is legal or not: > ` > ` > `Type > ` T = real; > ` R = Record > ` T: integer; > ` D: T; > ` end; > ` > ` B = Record > ` T: integer; > ` C: Record > ` D: T; > ` end; > ` end; > ` > `In particular, is field D in record R of type T or is it an illegal definition? > `Similarly for field D in record C. I am not interested in what a particular > `implementation does, just what the standard says about it. > ` > >Legal, because field names are in a different ``namespace'' than other >identifiers. In fact each record type has its own namespace. >-- >Piet van Oostrum, Dept of Computer Science, University of Utrecht >Padualaan 14, P.O. Box 80.089, 3508 TB Utrecht, The Netherlands >Telephone: +31-30-531806. piet@cs.ruu.nl (mcvax!hp4nl!ruuinf!piet) No, it is not legal. Pascal is not C. The text that follows is from ANSI/IEEE 770 X3.97-1983 (left my copy of ISO 7185 at home). On this point, and most others, the two standards agree. 6.2.2.1. Each identifier or label contained by the program-block shall have a defining-point. 6.2.2.2. Each defining-point shall have a region that is a part of the program text, and a scope that is a part or all of that region. 6.2.2.5. When an identifier or label has a defining-point for region A and another identifier or label having the same spelling has a defining-point for some region B enclosed by A, then region B and all regions enclosed by B shall be excluded from the scope of the defining-point for region A. 6.2.2.6. The region that is the field-specifier of a field-designator shall be excluded from the enclosing scopes. From Section 6.4.3.3: The occurrence of an identifier in the identifier-list of a record-section of a fixed-part of a field-list shall constitute its defining-point as a field-identifier for the region that is the record-type closest-containing the field-list, and shall associate the field-identifier with a distinct component, which shall be designated a field, of the record-type and of the field-list. Section 6.2.2.6 makes field references legal where the field-identifier has the same spelling as an identifier defined in an enclosing region. It does not apply to the cases shown in the example. Section 6.4.3.3 specifies that the region of a field-identifier defined in a record type is the closest-containing record type. Therefore, the scope of any identifier with the same spelling as a field-identifier defined in a record-type is excluded from the region that is the record type. Therefore, in both record-types, T refers to the field-identifiers, not the type-identifiers. Yours truly, Bob Corbett uunet!elxsi!corbett ucbvax!sun!elxsi!corbett