qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is


From: Thomas Huth
Subject: Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled
Date: Mon, 18 Nov 2019 10:28:29 +0100
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.2.0

On 18/11/2019 10.25, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <address@hidden> writes:
> 
> [...]
>> The related question is, is it OK to use size_t to iterate over an array?
>>
>>   for (size_t i = 0; i < ARRAY_SIZE(array); i++) {
>>     ...
>>   }
> 
> My rule of thumb on integer types is "whatever lets me avoid
> not-obviously-safe conversions (implicit ones in particular) with the
> least type cast clutter.
> 
> Quite often, int fits the bill.  But not always.
> 
> To reply to your example: depends on what's hiding in the ... :)

The problem here is that ARRAY_SIZE() gives you an size_t, so the
compiler might complain about comparing signed int with unsigned size_t.

Thus if i is only used as array index in the "..." part, I think it's
fine to use size_t for i here.

 Thomas




reply via email to

[Prev in Thread] Current Thread [Next in Thread]