Programming style with arrays, summary
Karl Heuer
karl at haddock.ISC.COM
Tue Jun 7 01:40:59 AEST 1988
In article <778 at dick.cs.vu.nl> dick at 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 at haddock.isc.com), The Walking Lint
Followups to comp.lang.c.
More information about the Comp.lang.c
mailing list