Prof. Harley Flanders wrote:
This SHOULD NOT work in BP or any flavor of Pascal, any more than the following should work:
const Digit: array[0..255] of 0..9 = 123456789101112;
A string is a different data type than an array of char, with a lot of different methods.
ISO 7185, 6.4.3.2:
: Any type designated packed and denoted by an array-type having as its : index-type a denotation of a subrange-type specifying a smallest value of 1 and : a largest value of greater than 1, and having as its component-type a : denotation of the char-type, shall be designated a string-type. : : The correspondence of character-strings to values of string-types is obtained : by relating the individual string-elements of the character-string, taken in : textual order, to the components of the values of the string-type in order of : increasing index.
So a packed array of char is indeed a string. (Both BP and GPC don't require packed here, but otherwise it's the same.)
I am surprised tht BP identifies short arrays of char with short strings.
In this regard, BP is standard-compliant ...
Would (and should) this work?
program foo;
var ch1, ch2, ch3: array[1..100] of char;
begin ch1 := '123'; ch2 := '456'; ch3 := ch1+ch2; (* or ch3 := Concat(ch1, ch2); *) Writeln(ch3, ' ', Length(ch3)); end.
I say absolutely not. HF
Yes, it does. Adding `packed' and declaring `Output', it's valid Extended Pascal, AFAICS.
BP doesn't allow this, so it's not standard-compliant here.
ISO 10206:
: 6.4.3.3.1 General : : A stringÂtype shall be a fixedÂstringÂtype or a variableÂstringÂtype or the : required type designated canonicalÂstringÂtype. Each stringÂtype value is a : value of the canonicalÂstringÂtype. : : Each value of a stringÂtype shall be structured as a oneÂtoÂone mapping from : an indexÂdomain to a set of components possessing the charÂtype. The : indexÂdomain shall be a finite set that is empty or that contains successive : integers starting with 1. : : NOTE --- StringÂtypes possess properties that allow accessing a substring : (see 6.5.6) and reading from a textfile (see 6.10.1). StringÂtype values may : be used as the actualÂparameter corresponding to a value parameter : possessing a stringÂtype (see 6.7.3.2), used as the actualÂparameter : assigned to a conformant actualÂvariable possessing a fixedÂstringÂtype and : conforming to a valueÂconformantÂarrayÂspecification (see 6.7.3.7.2), : assigned to a variable possessing a stringÂtype (see 6.9.2.2), written to a : textfile (see 6.10.3.6), used with the relationalÂoperators (see 6.8.3.5), : and used with the string concatenation operator (see 6.8.3.6). See also : 6.4.5 and 6.4.6.
: 6.4.3.3.2 FixedÂstringÂtypes : : A subrangeÂtype shall be designated a fixedÂstringÂindexÂtype if and only if : the expression in the first subrangeÂbound in the subrangeÂtype is : nonvarying (see 6.8.2), does not contain a discriminant identifier, and : denotes the integer value 1. Any type designated packed and denoted by an : arrayÂtype having as its indexÂtype a denotation of a : fixedÂstringÂindexÂtype and having as its componentÂtype a denotation of the : charÂtype, shall be designated a fixedÂstringÂtype.
: 6.4.6 AssignmentÂcompatibility : : A value of type T2 shall be designated assignmentÂcompatible with a type T1 : if any of the following six statements is true: : : f) T1 and T2 are compatible, T1 is a stringÂtype or the charÂtype, and the : length of the value of T2 is less than or equal to the capacity of T1 : (see 6.4.3.3). : : At any place where the rule of assignmentÂcompatibility is used to require a : value of the canonical stringÂtype to be assignmentÂcompatible with a : fixedÂstringÂtype or the charÂtype, the canonical stringÂtype value shall : be treated as a value of the fixedÂstringÂtype whose components in order of : increasing index shall be the components of the canonicalÂstringÂtype value : in order of increasing index followed by zero or more spaces.
Frank