boolean datatype

Mike Wexler mike at peregrine.UUCP
Tue Jun 10 07:09:18 AEST 1986


In article <705 at wjvax.wjvax.UUCP> brett at wjvax.UUCP (Brett Galloway) writes:
>In article <393 at peregrine.UUCP> mike at peregrine.UUCP (Mike Wexler) writes:
>>Another feature I would like to have is a range data type.  I don't
>
>I would prefer an operator that merely generated an integral type based on
>a number of bits requested, not based on a desired range.  For example,
>on a machine with 8-bit char, 16-bit short, 32-bit int, and 64-bit long,
>bittype(8) == char; bittype(9) == short; bittype(31) == int; and so on.
This is an interesting idea, but has many disadvantages.  You can't even
optionally turn on range checking, have the compiler check for range errors,
have the compiler do things like generate a jump table for a switch statement
knowing that the variable being switched on has a maximum value of 3, etc...

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.

If the reason for you suggestion is that run-time range checking is expensive.
This could be solved the same way it is handled on arrays, i.e. don't do it.
You can always add an option to the compiler to turn on range checking.
-- 
Mike Wexler
Email address:(trwrb|scgvaxd)!felix!peregrine!mike
Tel Co. address: (714)855-3923
;-) Internet address: ucivax at ucbvax.BERKELY.EDU!ucivax%felix!mike at peregrine :-(



More information about the Comp.lang.c mailing list