avifil32: Removed sign comparison warning (sizeof expresions)
mstefani at redhat.com
Mon Aug 23 07:11:58 CDT 2010
Andrey Turkin wrote:
> On Monday 23 August 2010 13:16:07 Michael Stefaniuc wrote:
>> IMHO gcc is *wrong* in emitting a warning there. sizeof(PCMWAVEFORMAT)
>> is a compile time constant and gcc can see that sizeof(PCMWAVEFORMAT)
>> falls well inside the number range expressible by a LONG. Logically
>> there is no difference between
>> formatsize <= sizeof(PCMWAVEFORMAT)
>> formatsize <= 16
>> One gives a bogus warning and the other doesn't.
> C99 std (para 18.104.22.168.4) states following about sizeof operator:
> "...its type (an unsigned integer type) is size_t, deﬁned in <stddef.h> (and
> other headers)."
> sizeof result is a compile-time constant but, unlike numeric constants, its
> type must always be size_t so gcc does the correct thing here.
That's actually not the problem but the "value preservation rule"
especially the "unsigned preservation rule". As sizeof(LONG) <=
sizeof(size_t) the formatsize will be promoted to an unsigned. Iff
formatsize is negative it will produce a big unsigned integer.
So I'll retract my critique of gcc (in this case as the compiler cannot
know what values formatsize will hold) and blame the C standard instead.
More information about the wine-devel