What is standard, and what isn't?_(re)

Wed, 30 Apr 1997 13:09:32 +0200 (MET DST)


According to Berend de Boer:
> If you want something 'difficult' to do , implement integer and string
> value arrays :-)

Not too difficult:  Integer arrays can be treated by a simple byte
compare; for string arrays the compiler must generate a loop.  This can be
done for records, too:  The compiler can do a loop through the fields of
the record.  (User programs cannot do that. :-P)

> Certainly: see the examples in 6.8.4

Thanks a lot!  I didn't find that.  Why wasn't there a single word about
this in 6.4.7, 6.4.8???

> I think one implements it as:
> 
> Type
>   String ( Capacity: Integer ) = record
>     length: Integer;
>     String: packed array [ 1..Capacity+SizeOf(Char) ] of Char;
>   end (* String *);

It's "1..Capacity + 1".  (Increasing the index by one adds one char.)

(And it's still an exception since you write "MyStr [ i ]", not
"MyStr.String [ i ]".)

> However length is not specified in the standard, so it should not be
> accessible with Extended Pascal. You can always use length(MyStr) to
> achieve the same functionality. 

What about the following:

  * Default mode (and Extended Pascal mode):  The length field cannot
    be accessed (except with "length ( MyStr )".)

  * With extended syntax (*$X+*):  The length field can be read- and
    write-accessed.

Okay like that?  Or perhaps better to have it in default mode, too,
and to switch it OFF in Extended Pascal mode?  I think it's best as
above because you should assign a new length to a string only if you
know exactly what you are doing.

Greetings,

    Peter

  Dipl.-Phys. Peter Gerwinski, Essen, Germany, free physicist and programmer
peter.gerwinski@uni-essen.de - http://home.pages.de/~peter.gerwinski/ [970201]
 maintainer GNU Pascal [970420] - http://home.pages.de/~gnu-pascal/ [970125]


Peter Gerwinski (peter@agnes.dida.physik.uni-essen.de)

HTML conversion by Lluís de Yzaguirre i Maura
Institut de Lingüística Aplicada - Universitat "Pompeu Fabra"
e-mail: de_yza@upf.es