[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
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, (continued)
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Michael S. Tsirkin, 2019/11/15
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Peter Maydell, 2019/11/15
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Peter Maydell, 2019/11/15
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Thomas Huth, 2019/11/15
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Philippe Mathieu-Daudé, 2019/11/15
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled, Markus Armbruster, 2019/11/18
- Re: [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled,
Thomas Huth <=