Path: utzoo!utgpu!water!watmath!clyde!bellcore!rutgers!mailrus!cornell!rochester!bbn!bbn.com!mesard From: mesard@bbn.com (Wayne Mesard) Newsgroups: comp.lang.c Subject: Re: Passing sizes of arrays without a separate argument for the length Message-ID: <29855@bbn.COM> Date: 20 Sep 88 13:38:38 GMT References: <8809191507.AA17512@ucbvax.Berkeley.EDU> Sender: news@bbn.COM Lines: 28 From article <8809191507.AA17512@ucbvax.Berkeley.EDU>, by U23405@UICVM (Michael J. Steiner): > 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] If I were to adopt your scheme, I'd want to do it consistently, since I would otherwise hopelessly confuse myself and anyone reading my code (if A[0] was sometimes data, and other times size info). But most of the time I either don't need to know an array's length: e.g., do you want to store a strings allocated size, or it's current length?; or I get this information elsewhere: from a #define'd constant (as should be the case in your example). This means that most of the time I'd be wasting the storage in the zeroth element of the array as well as processing time to assign it the length of the array unnecessarily. And that's to say nothing of the inefficiency of having to dereference to get the size (especially when the array is a float) when the alternative is accessing a parameter whose value is most likely in a register (again, as in your example). Don't try to reinvent Pascal. We still haven't recovered from the last time it was attempted:-) -- unsigned *Wayne_Mesard(); The last thing one knows in constructing MESARD@BBN.COM a work is what to put first. BBN, Cambridge, MA -- Blaise Pascal