Array Declarations

COTTRELL, JAMES cottrell at nbs-vms.ARPA
Fri Aug 30 06:04:51 AEST 1985


/*
> Not really a bite, but I remember when I was first learning C
> I was quite bewildered by the fact that you couldn't really
> declare your own 'argv', that is, you couldn't declare an
> array of pointers to fixed length buffers except perhaps by:
> 
> char *myargv[] = {
> 	"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
> 	"\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0",
> 
> I mean, argv seemed kinda holy to me, disturbing.
> 
> 	-Barry Shein, Boston University
> 
> P.S. I know argv is var length, but that would be even harder to declare!

Yeah. C will only create hidden literals of type char array. Wouldn't it
be nice to use expressions like `intptr = &2;' instead of the more
readable & nonportable `intptr = "\2\0\0\0";' (VAX) :-) Seriously tho,
remember DEC Fortran's `vectored arrays'? Why not get rid of `real'
arrays as well, & make them all pointers. When we declare: 

		int	array[3][5];

let's really let the compiler do:

		int	??[15];
		int	*?[3] = { ?? + 0, ?? + 5, ?? + 10};
		int	**array = ?;

where `?' & `??' are invisible `names' known only to the compiler.
Forgive me if I got the subscripts backwards. This would lose for one
dimensional arrays & constant references to multidimensional arrays, but
gain speed on random refs to multiple arrays. The extra space is the
price one pays for consistancy. Or maybe only higher dimension arrays
should be vectored. To gain vectoring one would tack on `[1]' to an
array name or use the (nonexistent) keyword `vectored'. Or maybe nobody
cares. Just idle thoughts.

	jim 		cottrell at nbs
*/
------



More information about the Comp.lang.c mailing list