Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!mnetor!seismo!ut-sally!im4u!rutgers!sri-unix!sri-spam!mordor!lll-tis!ptsfa!ihnp4!alberta!auvax!rwa From: rwa@auvax.UUCP (Ross Alexander) Newsgroups: comp.lang.c Subject: Re: type-indexed arrays (was: enum - enum ?) Message-ID: <184@auvax.UUCP> Date: Fri, 12-Jun-87 15:09:09 EDT Article-I.D.: auvax.184 Posted: Fri Jun 12 15:09:09 1987 Date-Received: Sun, 21-Jun-87 01:42:22 EDT References: <139@starfire.UUCP> <516@haddock.UUCP> <20540@sun.uucp> <526@haddock.UUCP> Organization: Athabasca U., Alberta, Canada Lines: 51 Summary: about a[ short ]... In article <526@haddock.UUCP>, karl@haddock.UUCP (Karl Heuer) writes: > Some machines can support a[short] with no trouble, but that would raise > the question of which types a conforming implementation is *required* > to support (and hence can be used in a portable program) [...] and a little further along, > Now, we could assert that [the compiler] must support *all* types > as subscripts, and that "int a[int]" will, if necessary [...] and yet further, > Incidentally, I am not suggesting that this feature be incorporated into the > new standard -- I realize there's very little hope for that. However, I *do* > believe it is a good idea (at least for enum) [...] I can think of only one little quibble with the above: C arrays are considered to begin with the zero'th element and end at the N-1'th element, right? So to declare something as int array[ short ]; implies that array[] has members indexed by -1, -2, -3, and so on ('short' is a signed type, no?). So Karl will also have to think of some way to introduce the declaration of array index bases, as well as array index ranges, a la Algol-60 or Pascal; and this then introduces a rather large can of worms when pointers to based arrays are passed around. Say I declare an array int demo[ 21 : -10 ]; which I define to mean 'an array of ints, called demo, 21 ints long, first element is demo[ -10 ]'. Fine. Now, what is the value of the token 'demo' ? Is it '& demo[ -10 ]' ? Is it '& demo[ 0 ]' (this is K&R's idea of 'demo', I think) ? And further, when I then code up something like 'frobozz( 2, "hi there", demo );' and frobozz() looks like double frobozz( a, b, c ); int a; char * b; int c[]; { /* and so on... */ what is the allowable range of indicies of c[] ? -10 .. +10 ? 0 .. 20 ? Beats _me_ :-). As a quick out (because I _do_ like the basic idea), how about saying that subscript types must be unsigned? ...!ihnp4!alberta!auvax!rwa Ross Alexander @ Athabasca University