Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!seismo!lll-crg!styx!nike!cad!pavepaws!keppel From: keppel@pavepaws.berkeley.edu (David Keppel) Newsgroups: net.lang.c Subject: Re: boolean datatype Message-ID: <561@cad.BERKELEY.EDU> Date: Tue, 10-Jun-86 10:10:32 EDT Article-I.D.: cad.561 Posted: Tue Jun 10 10:10:32 1986 Date-Received: Fri, 13-Jun-86 02:10:20 EDT References: <5498@alice.uUCp> <1462@mmintl.UUCP> <852@bentley.UUCP> Sender: news@cad.BERKELEY.EDU Reply-To: keppel@pavepaws.UUCP (David Keppel) Distribution: net Organization: CAD Group, U.C. Berkeley Lines: 38 Keywords: byte compilers word Summary: control over speed Disorganization: University of California, Berkeley In article <399@peregrine.UUCP> mike@peregrine.UUCP (Mike Wexler) writes: >It also puts the burden on the user to figure out how many bits are needed >to store a particular number. This could lead to either less efficient code >or nonportable code due to problems with signed/unsigned variables. For >instance if I say I want a range of 1 thru 7 the compiler could store this >in a signed or unsigned variable depending on which is most efficient. Now we have issues about whether we want an range 1..7 variable that is fast (on most machines an int) or small (byte or even bitfields). To handle this, you probably want to add keywords (yuk ;-) like "fast" and "small" so that you can say fast int range [1..7] foobar = 5; small int range [1..7] barbaz = 5; to get range checking when compiled with the right flag, but no speed penalty when compiled without, for the first case, and to get as small an int (most likely a byte) in the second case, even when compiled without the bounds-test flag. One problem I saw long ago in an intro class was along the lines of: int range [1..7] foobar; : foobar = 1; while (foobar <= 7) { stuff_to_do (foobar); foobar += 1; } [ this is a bad example, but short ] The problem here is that you want to restrict 'foobar' to have usable values 1..7, but must declare it 1..8 (or 0..7) or else write some messy code. I think that the prof. proposed that range-valued variables should be used very cautiously. :-D avid K eppel ..!ucbvax!pavepaws!keppel "Learning by Osmosis: Gospel in, Gospel out"