Waldek Hebisch wrote:
Consider the following program:
program fstr(output); type sat = packed array [1..16] of 'K'..'O'; var sa : sat; begin sa := 'OK'; writeln('Sizeof(sa) = ', Sizeof(sa)); writeln(sa) end .
ATM it "works". However, it seems that this program is illegal. Namely ISO says:
: 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
And later it again speaks about `the char-type'. So it seems that subranges of char type are _not_ allowed as component types of strings.
There is a (maybe somewhat curious) definition of strings in the ISO 7185 Pascal Report (third edition) in section 6.2:
"An array type is called a *string type* if it is packed, if it has as its component type the predefined type *Char* and if it has as its index type a subrange of *Integer* from 1 to n, for n greater than 1"
The report cleary speaks of "the predefined type Char". But, if I am correct, the definition seems to imply that we also have to reject (in iso modes) the following
{$standard-pascal} program teststr( Output); var s: packed array[ 1..1] of char; begin s:= '?'; writeln( s) end.
GPC correctly rejects (in iso modes) an array of char as a string type if the array is not "packed".
Form implementation point of view subranges can be packed more tightly then char type, so such restriction make some sense.
Now, the question is what shall we do? And do you agree with my reading of the standard? Shall we disallow the program above. Or maybe accept it as an extension, but report an error in standard mode.
The latter, I would say. Will there be any consequences when GPC starts to support Unicode character sets ?
Regards,
Adriaan van Os