[comp.lang.c] Programming style with arrays, summary

karl@haddock.ISC.COM (Karl Heuer) (06/06/88)

In article <778@dick.cs.vu.nl> dick@cs.vu.nl (Dick Grune) writes:
>	if (p >= &array[N]) ...
>	for (p = &array[0]; p < &array[N]; 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.

It's not the size of a pointer that matters; it's just a question of what is
the maximum size of an array.  (I.e., if you have 4-byte pointers but no array
can ever have more than 65535 elements, then a 2-byte int will suffice.)  This
has nothing to do with "&array[N]" vs. "array+N"; either both will work, or
neither.

Karl W. Z. Heuer (ima!haddock!karl or karl@haddock.isc.com), The Walking Lint
Followups to comp.lang.c.