Pascal Macro Compiler
Frank Heckenbach
ih8mj at fjf.gnu.de
Sun Jul 17 15:34:17 CEST 2005
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 stringtype shall be a fixedstringtype or a variablestringtype or the
: required type designated canonicalstringtype. Each stringtype value is a
: value of the canonicalstringtype.
:
: Each value of a stringtype shall be structured as a onetoone mapping from
: an indexdomain to a set of components possessing the chartype. The
: indexdomain shall be a finite set that is empty or that contains successive
: integers starting with 1.
:
: NOTE --- Stringtypes possess properties that allow accessing a substring
: (see 6.5.6) and reading from a textfile (see 6.10.1). Stringtype values may
: be used as the actualparameter corresponding to a value parameter
: possessing a stringtype (see 6.7.3.2), used as the actualparameter
: assigned to a conformant actualvariable possessing a fixedstringtype and
: conforming to a valueconformantarrayspecification (see 6.7.3.7.2),
: assigned to a variable possessing a stringtype (see 6.9.2.2), written to a
: textfile (see 6.10.3.6), used with the relationaloperators (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 Fixedstringtypes
:
: A subrangetype shall be designated a fixedstringindextype if and only if
: the expression in the first subrangebound in the subrangetype 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
: arraytype having as its indextype a denotation of a
: fixedstringindextype and having as its componenttype a denotation of the
: chartype, shall be designated a fixedstringtype.
: 6.4.6 Assignmentcompatibility
:
: A value of type T2 shall be designated assignmentcompatible with a type T1
: if any of the following six statements is true:
:
: f) T1 and T2 are compatible, T1 is a stringtype or the chartype, 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 assignmentcompatibility is used to require a
: value of the canonical stringtype to be assignmentcompatible with a
: fixedstringtype or the chartype, the canonical stringtype value shall
: be treated as a value of the fixedstringtype whose components in order of
: increasing index shall be the components of the canonicalstringtype value
: in order of increasing index followed by zero or more spaces.
Frank
--
THANK YOU, EUROPEAN PARLIAMENT, for rejecting one of the most
dangerous stupidities: http://swpat.ffii.org/log/05/ep0706/
Frank Heckenbach, frank at g-n-u.de, http://fjf.gnu.de/, 7977168E
More information about the Gpc
mailing list