[Top][All Lists]

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

Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary

From: Eric Blake
Subject: Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h"
Date: Fri, 29 Jun 2018 12:03:30 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0

On 06/29/2018 10:02 AM, Daniel P. Berrangé wrote:
Are you suggesting this?

#define KiB     (INT32_C(1) << 10)
#define MiB     (INT32_C(1) << 20)
#define GiB     (INT32_C(1) << 30)

#define TiB     (INT64_C(1) << 40)
#define PiB     (INT64_C(1) << 50)
#define EiB     (INT64_C(1) << 60)

Maybe, but then '8 * GiB' overflows, rather than giving a 64-bit result.

This feels dangerous to me as now the calculation may or may not be 32-bit
or 64-bit depending on which constant you happen to pick. I think this
inconsistency is going to be surprising to both devs and reviewers leading
to bugs.

Being consistently 64-bit may be annoying, but it's easy enough to reason about, compared to worrying whether an overflow will happen.

Did you consider just adding unsigned versions  ?  eg UKiB, UMiB, UGiB. It
is a bit ugly but is has the benefit of being obvious whether you're intending
the calculation  to be signed vs unsigned.

That might also be worthwhile, although I'd tend towards the name KiBU instead if UKiB (since I'm already used to U as a suffix).

Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org

reply via email to

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