integer types
Chris Torek
chris at umcp-cs.UUCP
Sat Feb 2 05:26:12 AEST 1985
Actually, there are a couple of different problems to be solved, and
subranges don't seem to be the right solution for all of them.
1. You want a variable whose value is to always be contained within
some particular range (e.g., array indicies). Subrange types
(especially runtime-checked types) are nice.
2. You want a variable whose value can be in *at least* some particular
range. Here subrange types that *are not* checked at run time
seem to work well (though if there is no checking, calling it a
subrange seems misleading, to me).
3. You want a variable whose value is in the largest possible range.
Here subranges fail miserably, because you can't write
[-infinity..infinity], and even if you could, the machine probably
wouldn't support *that* (we won't mention lisp bignums). If you
have a ``minint'' and ``maxint'' that might work, but perhaps the
machine can (with some speed degradation perhaps) support something
bigger than ``integers''.
Anyway, subranges have their uses. But since C hasn't got subranges,
if you want (1) or (2), use typedefs, preferably in machine-dependent
header files. In fact, typedefs will work for (3) also. So why aren't
you using them? :-)
--
(This line accidently left nonblank.)
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7690)
UUCP: {seismo,allegra,brl-bmd}!umcp-cs!chris
CSNet: chris at umcp-cs ARPA: chris at maryland
More information about the Comp.lang.c
mailing list