🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3255

Re: Modula2 for C programmers?

#3255
From: granville
Date: Wed, 07 Feb 1996 10:04
60 lines
3221 bytes
In article <4f64pd$qk7@seagoon.newcastle.edu.au>, peter@fourier.newcastle.edu.au (Peter Moylan) writes:
> 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.

 Well, almost never....
This is useful if you want to send REALS over a comms link, as BINARY
BYTE sized data,
 IN this case, the MOST PORTABLE and safest way to do the 'cast' is to 
use a VARIANT RECORD, of 4 bytes overlayed on a REAL
 The ISO has a 'tagless' variant record, which provides a good way to
save RAM, and choose at access time between BITSET, WORD, REAL etc.



> 
> --
> Peter Moylan                       peter@ee.newcastle.edu.au
>                            ftp://ee.newcastle.edu.au/pub/www/Moylan.html
===== Mandeno Granville FAX +64 9 6301 720, 128 Grange Rd Auckland 3 NZ ======
* Developers and suppliers of serious MicroController Embedded Control Tools *
* 89c2051, 89c1051 Emulator / ChipreProgrammers 			     *
* x51 C, Pascal & Modula-2 Compilers, Simulators, Emulators & FLASH Pgmrs    *
* Contact : Jim Granville . Email above.                                     *
Technical Details
Message-ID: <1996Feb7.230404.462@decus.org.nz>
Path: arc1-ca.pugleaf.net!decus.org.nz!granville
References: <DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk> <4f64pd$qk7@seagoon.newcastle.edu.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!decus.org.nz!granville
From: granville@decus.org.nz
Newsgroups: comp.lang.modula2
Subject: Re: Modula2 for C programmers?
Message-ID: <1996Feb7.230404.462@decus.org.nz>
Date: 7 Feb 96 23:04:04 +1300
References: <DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk> <4f64pd$qk7@seagoon.newcastle.edu.au>
Organization: DECUS New Zealand