🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #3181

Re: Modula2 for C programmers?

#3181
From: jguthrie
Date: Wed, 24 Jan 1996 13:11
40 lines
2719 bytes
Peter Moylan (peter@fourier.newcastle.edu.au) wrote:

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

(At least you don't call it coercion.)

I disagree with your last statement, because an awful lot of experience
suggests that it just isn't true in the most typical case.

Look, most everyone posting on this newsgroup programs for computers with
certain characteristics.  These computers store signed integers with 
twos-complement notation and use the IEEE floating-point formats.  These
computers use either 16 or 32 bits to hold INTEGERs and 32 or 64 bits to
hold REALs.  Leaving alone the "endianness" of the processor (which
really doesn't make any difference to what we're discussing) it is quite
possible to write portable code that makes use of casts to BITSET().

One of the other posts in response to my statement that "it isn't in PIM3C"
pointed out that such a cast rarely has any real semantic content.  However,
you could very easily require that the cast to BITSET results in the BITSET
that corresponds to the twos-complement representation of whatever the
INTEGER or CARDINAL (yeah, I know:  twos-complement doesn't really apply to
cards) was.  You would then also require that the conversion back do the
reverse thing.  That would be as portable as anything else in Modula-2,
and would handle the truly wierd cases (the ones-complement and
sign-magnitude computers) better than what C does, which is to use the
"natural" notation for the computer.

Why is it dangerous to recognize that all of these data values are composed
of bits?

I also take exception to your statement that you hardly ever need to use
such code, and therefore, it must not be important.  One of the main
reasons that I stopped using Modula-2 for the stuff I was doing
professionally was the difficulty I had coding CRC routines because I
didn't know about the casts to BITSET.  That may be a small use, but it
was vital to what I needed at the time.
Technical Details
Message-ID: <4e5b5u$7s5@weck.brokersys.com>
Path: arc1-ca.pugleaf.net!weck.brokersys.com!not-for-mail
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!weck.brokersys.com!not-for-mail
From: jguthrie@brokersys.com
Newsgroups: comp.lang.modula2
Subject: Re: Modula2 for C programmers?
Date: 24 Jan 1996 07:11:26 -0600
Organization: Executel/IBS Internet Services
Message-ID: <4e5b5u$7s5@weck.brokersys.com>
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>
NNTP-Posting-Host: weck.brokersys.com
X-Newsreader: TIN [version 1.2 PL2]