qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Thomas Huth <thuth@redhat.com>
To: "Markus Armbruster" <armbru@redhat.com>,
	"Philippe Mathieu-Daudé" <philmd@redhat.com>
Cc: "Peter Maydell" <peter.maydell@linaro.org>,
	"Eduardo Habkost" <ehabkost@redhat.com>,
	"Michael S. Tsirkin" <mst@redhat.com>,
	"QEMU Trivial" <qemu-trivial@nongnu.org>,
	"QEMU Developers" <qemu-devel@nongnu.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>
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	[thread overview]
Message-ID: <585e0317-d172-1bc9-e724-1cab2c7d2d63@redhat.com> (raw)
In-Reply-To: <874kz1y1sj.fsf@dusky.pond.sub.org>

On 18/11/2019 10.25, Markus Armbruster wrote:
> Philippe Mathieu-Daudé <philmd@redhat.com> 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	other threads:[~2019-11-18  9:30 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-15 14:50 [PATCH for-4.2] hw/i386: Fix compiler warning when CONFIG_IDE_ISA is disabled Thomas Huth
2019-11-15 15:34 ` Michael S. Tsirkin
2019-11-15 15:54 ` Peter Maydell
2019-11-15 15:54   ` Thomas Huth
2019-11-15 16:13     ` Paolo Bonzini
2019-11-15 16:13       ` Thomas Huth
2019-11-15 20:33         ` Philippe Mathieu-Daudé
2019-11-15 16:15     ` Peter Maydell
2019-11-15 16:12       ` Thomas Huth
2019-11-15 20:31         ` Philippe Mathieu-Daudé
2019-11-18  9:25           ` Markus Armbruster
2019-11-18  9:28             ` Thomas Huth [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=585e0317-d172-1bc9-e724-1cab2c7d2d63@redhat.com \
    --to=thuth@redhat.com \
    --cc=armbru@redhat.com \
    --cc=ehabkost@redhat.com \
    --cc=marcandre.lureau@redhat.com \
    --cc=mst@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-trivial@nongnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).