Path: utzoo!attcan!uunet!mcvax!botter!star.cs.vu.nl!dick From: dick@cs.vu.nl (Dick Grune) Newsgroups: comp.misc Subject: Programming style with arrays, enquiry Keywords: programming style, arrays Message-ID: <724@dick.cs.vu.nl> Date: 14 May 88 20:28:14 GMT Organization: V.U. Informatica, Amsterdam, the Netherlands Lines: 45 On the subject of programming style (a constant worry of mine), I should like to ask two (related) questions to the general programming public. When handling arrays, the bounds have to be described in some way. I know of three (consistent) methods to do so: 1. Address of first item and length. This is clean and can handle zero-length arrays. It gives, however, rise to incessant additions, since one wants the upper limit much more often than the length: if (p > array + length) error(); (or is it if (p >= array + length) error(); ?) 2. Address of first item and address of last item. This seems natural but you get +1 and -1 all over the place; I can hardly ever get this right and I have just given up correcting a piece of code someone else wrote in this style. 3. Address of first item and address of first non-item. This is unnatural and does not fit with everyday language, but it works. My code gets simpler (duller if you will), no more funny adjustments, the length of the array is the difference of the bounds, etc. The only problem with it is that there does not seem to be natural word or identifier for the first non-item (= the item after the last one). So my questions are: I. What do you use normally? and II. If you use method 3, what do you call the item past the last item? I will summarize to the net. (If it isn't clear yet, I use method 3 and clumsy names for the last plus one element). Dick Grune Vrije Universiteit de Boelelaan 1081 1081 HV Amsterdam the Netherlands dick@cs.vu.nl ...!mcvax!vu44!dick