[Oberon] Character arrays equality

Jörg Straube joerg.straube at iaeth.ch
Tue Apr 16 18:24:14 CEST 2019


Basically, a look into ORG.StringRelation should answer all your questions.
For your convenience see inline.

Jörg

> Am 16.04.2019 um 17:39 schrieb Артур Ефимов <arturefimov at gmail.com>:
> 
> In section 8.2.4 of "The Programming Language Oberon" ("Relations") we read:
> 
> Relations are Boolean. The ordering relations <, <=, >, >= apply to the numeric types, CHAR, and character arrays. The relations = and # also apply to the types BOOLEAN, SET, and to pointer and procedure types.
> 
> I have a few questions on character arrays specifically.
> 
> 1. Is expression "ABC" = "ABC" correct and does it evaluate to TRUE? (This might be important in some cases.)
Yes, and yes

> 2. What if one of the character arrays is a variable and not a constant?
The compiler handles both cases the same: a small loop over all characters until the first 0X is generated.
There is a small optimization in case of single character strings (eg „A“) that shrinks to a single CHAR and does not generate a loop but a single comparison.

> 3. What if both character arrays are variables?
see 2.

> 4. What if those character arrays (variables) have different length, though they hold logically-equal null-terminated strings?
The loop stops at the first 0X or at the position where the characters differ.

> 5. What if one (or both) of the character arrays is an open array with different lengths?
> 
> For example:
> VAR a, m: ARRAY 5 OF CHAR;
>   i: INTEGER;
> BEGIN
>   FOR i := 0 TO 4 DO a[i] := 0X; m[i] := 0X END;
>   a[0] := "A";
>   m[0] := "A"; m[3] := "M";
>   IF a = m THEN ... END
> END

a = m is TRUE

> Should we only compare characters before the first 0X?
yes. This is what the loop ORG.StringRelation generates does.

> Thanks!
> Arthur
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon



More information about the Oberon mailing list