🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3248

Re: Modula2 for C programmers?

#3248
From: Peter Moylan
Date: Mon, 05 Feb 1996 23:44
43 lines
2396 bytes
Mark Morgan Lloyd (mark_tbu@cix.compulink.co.uk) wrote:
>> Really? They do that?... hmmmm do you have any cases, where they do 
>> this, so i can avoid 'debugging' time.. ;{)

>Not that I can immediately lay hands on, I'm afraid, since home is 215 
>miles away and this was some years ago. ISTR it was something pretty 
>basic, I'm pretty sure (as Peter points out) that at least one of the 
>types was numeric.

It's also a while since I've checked it, but from memory here is
an example where TopSpeed violates the PIM rules:

     VAR a: LONGCARD;  b: REAL;  (* both 32-bit quantities *)
     BEGIN
          a := 5;  b := REAL(a);

For this example PIM prescribes a CAST operation, so that b will
end up being some strange-looking number that has nothing to do
with 5.0, whereas (if I remember correctly) TopSpeed will give
b the value 5.0.

Of course you could argue that the TopSpeed interpretation is
probably what the programmer really wanted, but that's a
separate issue; the fact is that you get non-portable code
without any use of SYSTEM.  I would have no argument with this
non-portability if the module had included something like
"FROM SYSTEM IMPORT CAST", but of course neither TopSpeed nor
PIM prescribes this.

To get a true type-cast in TopSpeed in this example is quite
tricky.  You have to cast to some intermediate 32-bit type,
and then type-cast again to the final destination.  You can't
use BITSET as the intermediate type, because in TopSpeed
BITSET is only 16 bits wide.

The good news is that it's very unlikely that anyone would
ever find a use for type-casting (as distinct from value
conversion) between LONGCARD and REAL, so the odds are that
this example will never turn up in real code.

--
Peter Moylan                       peter@ee.newcastle.edu.au
                           ftp://ee.newcastle.edu.au/pub/www/Moylan.html
Technical Details
Message-ID: <4f64pd$qk7@seagoon.newcastle.edu.au>
Path: arc1-ca.pugleaf.net!fourier.newcastle.edu.au!peter
References: <DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!fourier.newcastle.edu.au!peter
From: peter@fourier.newcastle.edu.au (Peter Moylan)
Newsgroups: comp.lang.modula2
Subject: Re: Modula2 for C programmers?
Date: 5 Feb 1996 23:44:45 GMT
Organization: The University of Newcastle
Message-ID: <4f64pd$qk7@seagoon.newcastle.edu.au>
References: <DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk>
Reply-To: peter@tesla.newcastle.edu.au
NNTP-Posting-Host: fourier.newcastle.edu.au
X-Newsreader: TIN [version 1.2 PL2]