Passing sizes of arrays without a separate argument for the length

George Kyriazis kyriazis at rpics
Wed Sep 21 00:23:57 AEST 1988


In article <8809191507.AA17512 at ucbvax.Berkeley.EDU> U23405 at UICVM (Michael J. Steiner) writes:
>I just got the idea of... well, let me give some examples:
>
>     ...
>     array[0] = 10;
>     somefunc(array);
>     ...

	It certainly looks a good idea, and most BASIC interpreters use that
method.  The size of the array (or a character string varaible) accompanies
the array itself.  It is very useful for variable length strings, but it
takes up space in fixed with strings.  It is also used in variable record
files.
	Notice that in your way, the array index is limited to 255
(sizeof(char) == 1), and sometimes you'll need an array with more than 255
elements.  One alternative will be something like that:

	struct	array	{
			int	length;
			type	*data;
			};

where 'type' is your favourite data type.



  George Kyriazis
  kyriazis at turing.cs.rpi.edu
------------------------------



More information about the Comp.lang.c mailing list