Article View: comp.lang.modula2
Article #3176Re: Modula2 for C programmers?
From: Peter Moylan
Date: Wed, 24 Jan 1996 00:03
Date: Wed, 24 Jan 1996 00:03
41 lines
2369 bytes
2369 bytes
jguthrie@brokersys.com wrote:
>Michel De Rosa (aliath@nyongwa.montreal.qc.ca) wrote:
>: Bit operations.. unfortunately with pre-ISO compilers, we where usually
>: stuck with multiplying or dividing by 2, for shift operations (rotate is
>: a tad more involved), now ISO also provides functions for those.. for
>: and/or/xor etc.. it's always been possible to do these, using the set
>: operators.. first coerce to a BITSET...
>Please don't talk down to me. I know how to manipulate bitsets, but
>do WHAT to a BITSET? As far as I know, NONE of the M2 compilers I have
>ever used allow me to convert between any kind of number and any kind of
>set. Otherwise, I'd have used that rather than mucking about with assembly
>language.
>I know that that isn't mentioned anywhere in PIM3C.
Yes it is. Let c be a CARDINAL (for example) and let b be a BITSET.
Then in ISO M2 you can write b := CAST(BITSET, c). In the PIM3
version of M2 the syntax is more obscure: b := BITSET(c).
The second form should be supported by any M2 compiler you can
lay your hands on.
A trick used by some programmers is to abuse the concept of
a record with variants:
TYPE Cheat = RECORD
CASE :BOOLEAN OF
| FALSE: bits: BITSET;
| TRUE: val: CARDINAL;
END (*CASE*)
END (*RECORD*)
Now, with x a variable of type Cheat, you can do bit operations
on x.bits, and the answer will turn up in x.val. This isn't
portable, but then operations requiring type-casting are
inherently non-portable in any language.
--
Peter Moylan peter@ee.newcastle.edu.au
ftp://ee.newcastle.edu.au/pub/www/Moylan.html
Technical Details
Message-ID:
<4e3t1f$d5q@seagoon.newcastle.edu.au>Path:
arc1-ca.pugleaf.net!fourier.newcastle.edu.au!peterReferences:
<erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com> <DLIGLJ.FDE@nyongwa.montreal.qc.ca> <4du11j$l31@weck.brokersys.com>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: 24 Jan 1996 00:03:58 GMT Organization: The University of Newcastle Message-ID: <4e3t1f$d5q@seagoon.newcastle.edu.au> References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com> <DLIGLJ.FDE@nyongwa.montreal.qc.ca> <4du11j$l31@weck.brokersys.com> Reply-To: peter@tesla.newcastle.edu.au NNTP-Posting-Host: fourier.newcastle.edu.au X-Newsreader: TIN [version 1.2 PL2]