Path: utzoo!attcan!uunet!husc6!bloom-beacon!gatech!uflorida!novavax!proxftl!bill From: bill@proxftl.UUCP (T. William Wells) Newsgroups: comp.misc Subject: Re: Programming style with arrays, enquiry Summary: ignore this unless you are dick@cs.vu.nl Keywords: programming style, arrays Message-ID: <182@proxftl.UUCP> Date: 17 May 88 17:35:22 GMT References: <724@dick.cs.vu.nl> Organization: Proximity Technology, Ft. Lauderdale Lines: 41 I tried to e-mail my response but that failed; readnews gave me a memory fault. Then I tried mail but I was unable to get it to acknowledge the address. So, could you give me an idea of the address to use with uucp? (E-mail to proxftl!bill please, assuming this is possible.) Anyway, here is my message: Methods 1 and 3 are equivalent: the first unused element IS the first element + length. (B.T.W: use if (p >= array + length) error(); instead of if (p > array + length) error(); ) I use both, depending on circumstances. Actually, when I use method 1, I write it: if (p >= &array[length]) error(); which is also method 3 except that the address is computed right then. An example would be: #define ARRAYLEN 1024 /* How long is my array? */ int Array[ARRAYLEN]; === if (p >= &Array[ARRAYLEN]) error(); Of course, if the array is dynamically allocated or on the stack, the end address computation has a penalty. If that penalty is too large, I do compute a pointer; its name is something like `array_end'. A word on terminology: in order to eliminate confusion, I consistently refer to the final element of an array as ...last or something to that effect; I refer to the place just after that element as ...end.