🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.modula2
Article #2584

Re: Report on defect in M2 vs C (Was Modula-2, Modula-3, C or C++)

#2584
From: Viet-Trung Luu
Date: Thu, 05 Oct 1995 18:36
62 lines
3551 bytes
On 3 Oct 1995, Bob Kitzberger wrote:

> Your C heritage is showing.

You're undoubtedly right. ;-)

> Generally you should NOT specify, nor depend, on the number of bits
> in an integer.  The number of bits used to represent an object
> is a very low-level concern, and shouldn't find its way into most code.
> 
> Instead, you should be concerned about the RANGE OF POSSIBLE VALUES,
> and let the compiler map this to the appropriate number of bits,
> a voltage range ;-) or whatever is most efficient on the platform.

Sure, I agree with that. My question is whether you should always have to 
declare a range or should you be able to expect a "reasonable" range by 
default. My assertion that integers should be at least 32 bits wide could 
be translated to something like "all integers should have, by default, a 
range of at least +/- 1000000000". It just happens that specifying 32 
bits is convenient.

> In Ada:
> 
> 	type Height_in_Feet is range 0 .. 1000;
> 
> This does require you to _think_ about what legal values of a type
> are, but also this avoids the many problems of assuming 8 bits is enough,
> or an int is enough, etc.  

But... when you're declaring a type, legal values might not be a linear 
range. What if legal values only included even numbers between 1 and 100 
and between 200 and 300? Where should a language stop in its ability to 
check ranges? Or should the programmer be able to write a routine to 
check whether a variable is legal at any given point (and have it run 
automatically)? The latter approach has its own problems: efficiency and 
a chicken-and-egg situation (or should the programmer have to both 
declare a linear range *and* a verification function?!?).

> I would agree that the language should allow you to specify how many
> bits are required, for those occassions where it really matters.
> Ada supports this as well:
> 
> 	type Device_Reg8 is range 0 .. 255;
> 	for Device_Reg8'Size use 8;

I wonder that should be necessary to have in a language (I'm not sure on 
this issue). Or should such things be relegated to libraries 
(standardized, hopefully)? After all, such things are rarely needed 
except when writing to standard file formats or when communicating with 
other machines. (Of course, there's always byte-ordering... should a 
programming language allow that to be specified?!? :-)

> One major annoyance with C is that you can neither specify a range of
> legal values, nor can you specify the storage required for an object
> (an 'int' in this case). 

Agreed. However, if 'int' was standardized as being 32-bit (some say that 
'long' serves that purpose), it would go a long way to solving those 
problems. (Note that the problems with 'int' are mainly on MS-DOG 
machines... where 'int' types are still 16-bit usually.)

- Trung
Technical Details
Message-ID: <Pine.SUN.3.91.951005003000.1000A-100000-100000-100000@lagrange.uwaterloo.ca>
Path: arc1-ca.pugleaf.net!mobius04.math.uwaterloo.ca!vluu

Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.modula2,comp.lang.modula3,comp.lang.c,comp.lang.c++,comp.lang.ada
Path: arc1-ca.pugleaf.net!mobius04.math.uwaterloo.ca!vluu
From: Viet-Trung Luu <vluu@lagrange.uwaterloo.ca>
Subject: Re: Report on defect in M2 vs C (Was Modula-2, Modula-3, C or C++) 
Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
Message-ID: <Pine.SUN.3.91.951005003000.1000A-100000-100000-100000@lagrange.uwaterloo.ca>
X-Sender: vluu@mobius04.math.uwaterloo.ca
In-Reply-To: <44scr8$9uf@rational.rational.com> 
Date: Thu, 5 Oct 1995 18:36:09 GMT
Content-Type: TEXT/PLAIN; charset=US-ASCII
Nntp-Posting-Host: mobius04.math.uwaterloo.ca
Mime-Version: 1.0
Organization: University of Waterloo