Path: utzoo!utgpu!water!watmath!clyde!bellcore!tness7!killer!pollux!dalsqnt!uunet!mcvax!botter!star.cs.vu.nl!dick
From: dick@cs.vu.nl (Dick Grune)
Newsgroups: comp.misc
Subject: Programming style with arrays, summary
Keywords: programming style, arrays
Message-ID: <778@dick.cs.vu.nl>
Date: 2 Jun 88 14:02:24 GMT
Organization: V.U. Informatica, Amsterdam, the Netherlands
Lines: 47


	Two weeks ago I posted an enquiry on the name of the first non-entry in
an array, to use as a limit in testing.  I received 7 answers, from which no
clear consensus emerged.

	Two people argue convincingly that using the number of elements and
using the address of the last+1 item is actually the same thing.  They advocate
tests like:

	if (p >= &array[N])
		error(...);

and loops like:

	for (p = &array[0]; p < &array[N]; p++)
		process(*p);

both of which look sane and understandable.  I seriously thought about adopting
these "templates" systematically in my coding, when I realized that for it to
work, you would have to declare N as a long.  Otherwise you lose on machines
with 2-byte ints and 4-byte pointers.  (I know, I know, the Kernighan & Ritchie
book does not allow these, but they do exist.)  Now this is something somebody
will go and make mistakes with, me first of all, and the point of the exercise
was to avoid errors.

	Back to names for the elusive element after all elements.  Suggestions
were:

	array_Nth,  array_last1,  array_guard,  array_meta,
	array_end (vs. array_last for &array[N-1]), array_limit;

all suggested once.  Going through my programs I see that I have used
array_limit, array_FF, array_first_not_in (vs. array_first_in,  I must have
been doing this by gross editing!) and array_end.

	I like the _meta; it means "past", "after"; but it needs an explanation
to be understood (but perhaps every word for this notion will).  Array_end and
array_limit sound more normal but do not convey the notion.  Perhaps a new
notion needs a new word.  In that case  _meta  is a good candidate.

					Dick Grune
					Vrije Universiteit
					de Boelelaan 1081
					1081 HV  Amsterdam
					the Netherlands
					dick@cs.vu.nl
					...!mcvax!vu44!dick