Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!pasteur!ucbvax!UICVM!U23405 From: U23405@UICVM (Michael J. Steiner) Newsgroups: comp.lang.c Subject: Passing sizes of arrays without a separate argument for the length Message-ID: <8809191507.AA17512@ucbvax.Berkeley.EDU> Date: 2 Sep 88 00:38:28 GMT Sender: usenet@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 47 I just got the idea of... well, let me give some examples: BEFORE - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - main() { char array[10]; ... somefunc(array,10); } void somefunc(array,max) char *array; int max; { int i; for (i = 1; i < max; ++i) ... } AFTER (MY IDEA) : - - - - - - - - - - - - - - - - - - - - - - - - - - - - main() { char array[10]; ... array[0] = 10; somefunc(array); } somefunc(array) char *array; { int i; for (i = 1; i < array[0]; ++i) ... } In other words, I had an idea of putting the maximum array dimension in the array itself. This should work with most arrays (since chars, floats, unsigneds, shorts, etc. can be converted to integers). Also, there is always room for the size of the array in array[0] (provided that the data starts at array[1], as in PASCAL), since arrays should have at least a few elements. Any comments or suggestions are appreciated. Michael Steiner Email: U23405@UICVM.BITNET