Path: utzoo!utgpu!attcan!uunet!lll-winken!lll-tis!ames!mailrus!uwmcsd1!leah!itsgw!imagine!rpics!kyriazis From: kyriazis@rpics (George Kyriazis) Newsgroups: comp.lang.c Subject: Re: Passing sizes of arrays without a separate argument for the length Message-ID: <1220@imagine.PAWL.RPI.EDU> Date: 20 Sep 88 14:23:57 GMT References: <8809191507.AA17512@ucbvax.Berkeley.EDU> Sender: news@imagine.PAWL.RPI.EDU Reply-To: kyriazis@turing.cs.rpi.edu (George Kyriazis) Organization: RPI CS Dept. Lines: 28 In article <8809191507.AA17512@ucbvax.Berkeley.EDU> U23405@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@turing.cs.rpi.edu ------------------------------