[comp.lang.pascal] array-types passed by value-ANSI standard

mackie@watdcsu.waterloo.edu (Computer Systems Group) (06/21/88)

    I have a question that deals with passing arrays by value
in the ansi standard. There seem to be two different interpretations
to the matter in the standard so I'm wondering if there is an expert
out there who can clarify the issue.

The book I am using as reference is AMERICAN NATIONAL STANDARD
PASCAL COMPUTER PROGRAMMING LANGUAGE - 1983

The issue involves when an array-type passed by value is
considered undefined.

First Interpretation : Section # 6.4.3.2

    "A value of an array-type does not therefore exist unless all of its
component values are defined. If the component-type has c values, then it
follows that the cardinality of the set of values of the array-type is c
raised to the power k."


I interpret this as meaning that if you use an array in which any
element is not defined, then the array should be treated as undefined
( so should generate an error when passed by value );

Second Interpretation : Section # 6.8.2.2

    "The state of a variable or activation result when the variable or
activation result does not have attributed to it a value specified by its
type shall be designated UNDEFINED. If a variable posseses a structured
type, the state of the variable when every component of the variable
is totally-undefined shall be designated TOTALLY-UNDEFINED.
Totally-undefined shall be synonymous with undefined for an
activation result or a variable that does not possess
a structured type."

I interpret this as if one of the elements of an array is defined, then
the array is considered to be defined. This is a recursive definition.
This seems to be a contradiction to the first interpretation.

Now to top this off, Test # 6.6.3.1-2 in the conformance
section in VERSION 3.1 of the PASCAL VALIDATION SUITE allows
passing of an array by value that is not completely defined.
( ie- it should not generate an error )

The equivalent test in Version 4.1 of the suite does the same
as previous one except it totally defines the array
before it is passed.


Is there anyone who can offer an opinion on this problem?

bobdi@omepd (Bob Dietrich) (06/23/88)

In article <4816@watdcsu.waterloo.edu> mackie@watdcsu.waterloo.edu (Computer Systems Group) writes:
>
>    I have a question that deals with passing arrays by value
>in the ansi standard. There seem to be two different interpretations
>to the matter in the standard so I'm wondering if there is an expert
>out there who can clarify the issue.

I just did something similar at last week's Joint Pascal Committee (JPC)
meeting.  Unfortunately, I don't have my wording here, but I'll
try to reconstruct it.  By the way, what I say here is my own opinion,
and should not be construed as an "official" view of any committee.
>
>The book I am using as reference is AMERICAN NATIONAL STANDARD
>PASCAL COMPUTER PROGRAMMING LANGUAGE - 1983

The same points apply to ISO 7185.
>
>The issue involves when an array-type passed by value is
>considered undefined.
>
>First Interpretation : Section # 6.4.3.2
>
>    "A value of an array-type does not therefore exist unless all of its
>component values are defined. If the component-type has c values, then it
>follows that the cardinality of the set of values of the array-type is c
>raised to the power k."
>
>
>I interpret this as meaning that if you use an array in which any
>element is not defined, then the array should be treated as undefined
>( so should generate an error when passed by value );

Yes. This is key.
>
>Second Interpretation : Section # 6.8.2.2
>
>    "The state of a variable or activation result when the variable or
>activation result does not have attributed to it a value specified by its
>type shall be designated UNDEFINED. If a variable posseses a structured
>type, the state of the variable when every component of the variable
>is totally-undefined shall be designated TOTALLY-UNDEFINED.
>Totally-undefined shall be synonymous with undefined for an
>activation result or a variable that does not possess
>a structured type."
>
>I interpret this as if one of the elements of an array is defined, then
>the array is considered to be defined. This is a recursive definition.
>This seems to be a contradiction to the first interpretation.

The first sentence you quote is important, in particular the phrase "a value
specified by its type". The second sentence is really just defining the term
"totally-undefined" for use elsewhere, and does not have a strong
relationship to the first sentence.

Basically, a value of a structured type can only be a structured value if all
of its components are defined. If ANY component is undefined, then the
structured value is "undefined". If ALL the components are undefined, then it
is "totally-undefined".

The interpretation centers around the phrase "a value specified by its type".
If any component of a structured variable is undefined, the variable itself
is undefined, and therefore does not possess a value specified by its type.
It then falls under the definition of undefined, and it is an error (see
6.7.1) to use an expression containing something that is undefined. Since
actual value parameters are expressions, passing such an array value is an
error.

The confusion caused by this paragraph is only made worse in Extended Pascal
by the new feature of user-defined initial states (the initial state of all
types in unextended Pascal is undefined). At the JPC meeting last week we
added text to clarify the concept of states and associated values, and moved
the text defining undefined to that section. Hopefully that will lessen the
confusion.
>
>Now to top this off, Test # 6.6.3.1-2 in the conformance
>section in VERSION 3.1 of the PASCAL VALIDATION SUITE allows
>passing of an array by value that is not completely defined.
>( ie- it should not generate an error )

It, like many of the tests in V3, was wrong. BTW, V5.0 is the most current.
>
>The equivalent test in Version 4.1 of the suite does the same
>as previous one except it totally defines the array
>before it is passed.
>
>
>Is there anyone who can offer an opinion on this problem?

Hope this helped.

				Bob Dietrich
				Intel Corporation, Hillsboro, Oregon
				(503) 696-4400 or 2092(messages x4188,2111)
		usenet:		tektronix!ogcvax!omepd!bobdi
		  or		tektronix!psu-cs!omepd!bobdi
		  or		ihnp4!verdix!omepd!bobdi