boolean datatype

David Keppel keppel at pavepaws.berkeley.edu
Wed Jun 11 00:10:32 AEST 1986


In article <399 at peregrine.UUCP> mike at 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"



More information about the Comp.lang.c mailing list