Article View: comp.lang.modula2
Article #3254Re: Modula2 for C programmers?
From: Michel De Rosa
Date: Tue, 06 Feb 1996 23:29
Date: Tue, 06 Feb 1996 23:29
76 lines
3481 bytes
3481 bytes
Peter Moylan (peter@fourier.newcastle.edu.au) wrote:
: 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
That's also my interpretation of what PIM prescribes..
: b the value 5.0.
Most annoying, especially since (as you point out later), JPI didn't
provide a true 'CAST' function.
: Of course you could argue that the TopSpeed interpretation is
: probably what the programmer really wanted, but that's a
Actually, i would argue (with said programmer), that he should probably
have used the already provided procedures (FLOAT/TRUNC/VAL) to do this..
: 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.
Mostly, i agree.. While i never thought the coercion mechanism (as described
in PIM) was broken, i can see that using SYSTEM.CAST as the benefit of
documenting the possible non-portable nature of the code..
: 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
Not only tricky, but in my opinion, without proper comments, the intent
of the code will be obscured..
Well there is an alternative (often abused, but should be faster and
clearer), and that's to use a tag-less variant record type, as in:
TYPE TransferTemplate = RECORD
CASE :BOOLEAN OF
0: longcard: LONGCARD;
|1: real: REAL;
END;
Oh well.. when you have to.. :{(
: 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.
Actually i do need this.. actually something very close, since i need to
access a data-file, that contains Turbo-Pascal Reals (those 48Bit Reals),
from TopSpeed..
Well thanks for the warning...
Ciao!
Michel De Rosa
aliath@nyongwa.montreal.qc.ca
Technical Details
Message-ID:
<DMDnx3.Azx@nyongwa.montreal.qc.ca>Path:
arc1-ca.pugleaf.net!mcrcim.mcgill.edu!nyongwa!aliathReferences:
<DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk> <4f64pd$qk7@seagoon.newcastle.edu.au>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.modula2 Path: arc1-ca.pugleaf.net!mcrcim.mcgill.edu!nyongwa!aliath From: aliath@nyongwa.montreal.qc.ca (Michel De Rosa) Subject: Re: Modula2 for C programmers? Message-ID: <DMDnx3.Azx@nyongwa.montreal.qc.ca> Organization: Radio Free Nyongwa, Montreal (Qc), Canada Date: Tue, 6 Feb 1996 23:29:27 GMT References: <DM2KB6.983@nyongwa.montreal.qc.ca> <DM3L4G.M6J@cix.compulink.co.uk> <4f64pd$qk7@seagoon.newcastle.edu.au> X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]