Another way (How not to write a loop)

Doug Gwyn gwyn at brl-smoke.ARPA
Fri Feb 19 08:27:35 AEST 1988


In article <16982 at watmath.waterloo.edu> rbutterworth at watmath.waterloo.edu (Ray Butterworth) writes:
-> >     auto size_t index;
-> >     index = sizeof(array) / sizeof(array[0]);
-> >     while (--index >= 0)
-The problem I was trying to point out is that much existing
-code wasn't written with perfect style, and this is yet another
-way in which otherwise correct code will break when it is ported
-to an ANSI compiler (as I found out the hard way).

The fact that the result of sizeof has an unsigned integral type is
not new with ANSI C.  UNIX C has been this way since around 1980 at
least.  You're getting confused since Berkeley didn't pick up this
change when they stole the pre-USG 3.0 C compiler (circa 1979) that
is included in their distribution.



More information about the Comp.lang.c mailing list