gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistent HIGH values with 'ARRAY OF CHAR'


From: Rudolf Schubert
Subject: Re: Inconsistent HIGH values with 'ARRAY OF CHAR'
Date: Thu, 11 May 2023 11:40:05 +0200 (CEST)

        Hi Gaius,

        I find handling of C-strings somehow 'difficult' or even ugly
        because of this terminating 0C. The idea of terminating a string
        (or as we say an ARRAY OF CHAR) with a 0C immediately shows 2
        disadvantages:

        1. we do not know the length of the string until we search the
        terminating 0C. Wouldn't it be much simpler just to have another
        variable which tells us the length?
        2. with 0C having this special meaning, 0C itself can never be
        part of our ARRAY. But sometimes this might be useful!

        But of course we now must live with this situation. So if we
        want to deal with 'real' C-strings we need this terminating 0C.
        Either as a 'real' CAHR which we put somewhere into memory or
        as some 'virtual' thing which we 'imagine' would be located
        beyond the very end of our ARRAY OF CHAR.

        And thus at different occasions we have no other chance than
        generating this 0C and putting it at the end of the ARRAY.

        Two such occasions are simple assignments to variables of TYPE
        ARRAY OF CHAR or when passing things as parameter to a PROCEDURE.

        For instance for a

        VAR
          str_c:                        ARRAY[0..2] OF CHAR;

        an assignment

        str_c := '';

        will in any case place 0C at index 0.

        str_c := 'a';

        will place 'a' at index 0 and 0C at index 1.

        str_c := 'abc';

        just places all characters into str_c but a 'real' 0C is
        put nowehere!

        I think this is the way to go also for passing parameters into
        a PROCEDURE. So yes, as you suggested, I think when passing just
        one literal character into our ARRAY OF CHAR we should also put
        a 'real' 0C at the end, i.e. right after this one character.


        As an aside: while playing a bit with strings I could trigger
        another ICE with this simple method:


        MODULE port_test8b_gm2;

        VAR
          str_a:                        ARRAY[0..0] OF CHAR;

        BEGIN                           (* MODULE port_test8b_gm2 *)
          str_a:='ab';
        END port_test8b_gm2.


        First there is a

        Warnung: string constant is too large to be assigned to the array

        but then I also see an ICE which I find a bit exaggerated;-)


BR

Rudolf

--
Rudolf Schubert                 \
Kirchstr. 18a                    \  mailto:rudolf@muc.de
82054 Sauerlach                   > http://www.dose.muc.de
Deutschland                      /
Tel. 08104/908311               /





reply via email to

[Prev in Thread] Current Thread [Next in Thread]