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 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

-- 
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