🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3185

Re: Modula2 for C programmers?

#3185
From: Martin Tom Brown
Date: Wed, 24 Jan 1996 09:52
48 lines
2600 bytes
In article <4e3t1f$d5q@seagoon.newcastle.edu.au>
           peter@tesla.newcastle.edu.au "Peter Moylan" writes:

> jguthrie@brokersys.com wrote:
> >Michel De Rosa (aliath@nyongwa.montreal.qc.ca) wrote:

> >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).

I think it might be a matter of taste, I generally prefer the look
of the latter (even if the syntax is more obscure) since it leaves
numerical expressions looking considerably less cluttered.

> The second form should be supported by any M2 compiler you can
> lay your hands on.

Indeed. I don't have the reference to hand but isn't   
	 b := VAL(BITSET, c) valid in PIM3 too ? 
 
> 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.

This can sometimes be useful. Inherently dangerous too.

Actually it can be portable provided that it contains a flag to say 
what data type is stored in it and your routines agree to abide by the 
rule of only using the data type that was last written to "Cheat" record.  
You have to be severely memory (ram) constrained to contemplate this.

Regards,
-- 
Martin Brown  <martin@nezumi.demon.co.uk>     __                CIS: 71651,470
Scientific Software Consultancy             /^,,)__/
Technical Details
Message-ID: <822477145snz@nezumi.demon.co.uk>
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!nezumi.demon.co.uk
References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com> <DLIGLJ.FDE@nyongwa.montreal.qc.ca> <4du11j$l31@weck.brokersys.com> <4e3t1f$d5q@seagoon.newcastle.edu.au>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!mail2news.demon.co.uk!nezumi.demon.co.uk
From: Martin Tom Brown <Martin@nezumi.demon.co.uk>
Newsgroups: comp.lang.modula2
Subject: Re: Modula2 for C programmers?
Date: Wed, 24 Jan 96 09:52:25 GMT
Organization: Nezumi
Message-ID: <822477145snz@nezumi.demon.co.uk>
References: <erico-1801961940460001@infinitehell.cnmat.berkeley.edu> <4dqusf$d7k@weck.brokersys.com> <DLIGLJ.FDE@nyongwa.montreal.qc.ca> <4du11j$l31@weck.brokersys.com> <4e3t1f$d5q@seagoon.newcastle.edu.au>
Reply-To: Martin@nezumi.demon.co.uk
X-NNTP-Posting-Host: nezumi.demon.co.uk
X-Newsreader: Demon Internet Simple News v1.29
X-Mail2News-Path: nezumi.demon.co.uk