Article View: comp.lang.modula2
Article #3201Re: Modula2 for C programmers?
From: Peter Moylan
Date: Mon, 29 Jan 1996 00:14
Date: Mon, 29 Jan 1996 00:14
43 lines
2589 bytes
2589 bytes
Mark Morgan Lloyd (mark_tbu@cix.compulink.co.uk) wrote:
>> neither does it do any sort of interpretation of the bits,
>> i.e. it's a straight copy of the bitmap, if you will..
>Watch it! I've argued this one in the past with TopSpeed, who IIRC under
>certain circumstances _do_ apply transformations.
TopSpeed introduced a lot of confusion with this one, but to a
large extent the blame should lie on some sloppy definitions
in the original definition of M2.
Experienced programmers know - or should know - that there
are two distinct categories of type conversion:
(a) value conversions, where a transformation is applied if
necessary to do things like converting the integer 2 to
the floating point number 2.0;
(b) type-casting, which is a simple re-naming of the type
without any modification of the bit representation.
Unfortunately PIM lumps these two things together under the
name "type transfer function", leaving the unsuspecting reader
with the impression that they are the same thing. Indeed they
are the same thing under certain circumstances (e.g. conversion
between CARDINAL and an enumerated type, which I think was the
example used in PIM), but not in all circumstances.
TopSpeed's solution was to say that type transfer is a type
conversion for arithmetic types, and a type-cast for all
other types. This is not, strictly speaking, consistent with
PIM, but in their defence one might say that they were trying
to clean up something that was badly conceived in PIM.
A better solution is to define two distinct operations called
(for example) CAST and VAL. This is what is done in the
ISO standard, and we'll get cleaner code if future programmers
use that feature. Regrettably the ISO standard also includes
the original "type transfer function" mechanism for the sake
of backward compatibility, so there's no way of stopping
programmers from using this nasty feature.
--
Peter Moylan peter@ee.newcastle.edu.au
ftp://ee.newcastle.edu.au/pub/www/Moylan.html
Technical Details
Message-ID:
<4eh3hp$18d@seagoon.newcastle.edu.au>Path:
arc1-ca.pugleaf.net!fourier.newcastle.edu.au!peterReferences:
<DLLvHL.3C4@nyongwa.montreal.qc.ca> <DLMz95.9r4@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: 29 Jan 1996 00:14:49 GMT Organization: The University of Newcastle Message-ID: <4eh3hp$18d@seagoon.newcastle.edu.au> References: <DLLvHL.3C4@nyongwa.montreal.qc.ca> <DLMz95.9r4@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]