🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #4259

Re: Cardinal numbers

#4259
From: Thomas M. Breeden
Date: Fri, 20 May 1988 19:06
75 lines
2910 bytes
In article <1101@sask.UUCP> intbook@sask.UUCP (Dave Daoust) writes:
   >
   >Is the following program legal?  What is displayed?
   >
   >
   >MODULE N;
   >FROM InOut IMPORT WriteCard, WriteLn;
   >PROCEDURE Out(S : ARRAY OF CHAR);
   >BEGIN
   >   WriteCard(HIGH(S), 0);
   >   WriteLn;
   >END Out;
   >BEGIN
   >   Out("");
   >END N.

The original PDP11 Modula-2 compiler (which I am still using) always
places a 0C at the end of any literal string, including '""'. Thus the
above HIGH(S) value is printed out as (and is) 0. For the above, SIZE(S)
is 1.

I believe most or all other M2 compilers do the same thing, but don't
think that it is specified in PIM2, 3rd edition. Is this standard or
becoming standard?

Another related thing that I have wondered about is the situation with
respect to dynamic arrays and LONGCARD vs. CARDINAL indices. ie, how is
the TYPE of HIGH() maintained correctly when the index could be a LONG...?

The TDI compiler for the Amiga will react to the following :

          MODULE N;
          FROM InOut IMPORT WriteCard, WriteLn;
          VAR  c :CARDINAL;
               a :ARRAY[0..65536] OF CHAR;
          BEGIN
          WriteCard(HIGH(a), 0); WriteLn;
          END N;

with a diagnostic on compiling that HIGH(a) is the wrong type. It does
seem to type it as LONGCARD.

Unfortunately, the situation is not so good for the following :

          MODULE N;
          FROM InOut IMPORT WriteCard, WriteLn;
          VAR  c :CARDINAL;
               a :ARRAY[0..65536] OF CHAR;

             PROCEDURE P(s:ARRAY OF CHAR);
             BEGIN
             WriteCard(HIGH(s), 0); WriteLn;
             END;

          BEGIN
          P(a);
          END N;

This compiles without error but prints out out HIGH(s) as a CARDINAL "1"
(ie, the first word, 68000 style, of the 32 bit value).
(Their release notes do warn about this bug, however).

Do other compilers that support both CARDINAL and LONGCARD TYPES and that
allow either to be array indices handle this better?

Is this a settled issue in the standardization efforts?

            - Tom Breeden
              tmb@virginia.EDU      -> Internet
              tmb@virginia          -> BITNET


            - Tom Breeden
              tmb@virginia.EDU      -> Internet
              tmb@virginia          -> BITNET
Technical Details
Message-ID: <888@virginia.acc.virginia.edu>
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!bloom-beacon!gatech!mcnc!uvaarpa!virginia!davinci.acc.Virginia.EDU!tmb
References: <1101@sask.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!attcan!uunet!husc6!bloom-beacon!gatech!mcnc!uvaarpa!virginia!davinci.acc.Virginia.EDU!tmb
From: tmb@davinci.acc.Virginia.EDU (Thomas M. Breeden)
Newsgroups: comp.lang.modula2
Subject: Re: Cardinal numbers
Keywords: HIGH, WriteCard
Message-ID: <888@virginia.acc.virginia.edu>
Date: 20 May 88 19:06:15 GMT
References: <1101@sask.UUCP>
Sender: acc@virginia.acc.virginia.edu
Reply-To: tmb@davinci.acc.Virginia.EDU (Thomas M. Breeden)
Organization: Biomedical Image Processing Cntr, Univ of Va.
Lines: 75