winmm: Sign-compare warning fix (Resend)
jjmckenzie51 at earthlink.net
Fri Dec 12 10:51:35 CST 2008
Michael Karcher <wine at mkarcher.dialup.fu-berlin.de> at: Dec 12, 2008 9:23 AM (MST) wrote about: RE: winmm: Sign-compare warning fix (Resend)
>Am Freitag, den 12.12.2008, 09:07 -0700 schrieb James Mckenzie:
>> > unsigned int i;
>> > ...
>> > for (i = sizeof(foo) / sizeof(foo) - 1; ~i; --i)
>> >Tested? No.
>> >Readable? Don't ask me... :-)
>> I understood it, but is not the goal to avoid the use of C++ constructs in WINE code?
>There is no C++ construct in that code. Still i-- would do the same and
>is more idiomatic C.
>> The real question is why convert a for loop to a while loop?
>After the last iteration, the --i (or i--) overflows. In a for loop, the
>step statement (the third statement in the loop head) is always executed
>before the test (the second statement in the loop head), so there is no
>way to prevent the overflow. While this is not a problem per se, as
>overflow of unsigned variables is well-defined, testing for "overflow
>just happended" tends to be more confusing to the readers than testing
>for "is at the end".
>If you use a while loop instead, you can arrange the test to be executed
>*before* the step is performed, so you have to abort on "i == 0 just
>finished" insted of "i == ~0U is next", the former being easier to
This is a definite improvement. Glad you caught it and thank you for the lesson in the use of structures vice arrays. I'll take a close look at the code and your change this weekend. I was caught by the use of sizeof(array) vice sizeof(struct), which do yeild different results.
More information about the wine-devel