[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
- [Qemu-trivial] [PATCH v5 00/46] Use the IEC binary prefix definitions, Philippe Mathieu-Daudé, 2018/06/25
- [Qemu-trivial] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/25
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Richard Henderson, 2018/06/27
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Igor Mammedov, 2018/06/27
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Eric Blake, 2018/06/27
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/28
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Eric Blake, 2018/06/29
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/29
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h", Daniel P . Berrangé, 2018/06/29
- Re: [Qemu-trivial] [Qemu-devel] [PATCH v5 01/46] include: Add IEC binary prefixes in "qemu/units.h",
Eric Blake <=
[Qemu-trivial] [PATCH v5 02/46] vdi: Use definitions from "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/25
[Qemu-trivial] [PATCH v5 03/46] x86/cpu: Use definitions from "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/25
[Qemu-trivial] [PATCH v5 07/46] hw/ivshmem: Use the IEC binary prefix definitions, Philippe Mathieu-Daudé, 2018/06/25
[Qemu-trivial] [PATCH v5 06/46] hw: Directly use "qemu/units.h" instead of "qemu/cutils.h", Philippe Mathieu-Daudé, 2018/06/25
[Qemu-trivial] [PATCH v5 05/46] hw: Use IEC binary prefix definitions from "qemu/units.h", Philippe Mathieu-Daudé, 2018/06/25
[Qemu-trivial] [PATCH v5 09/46] hw/scsi: Use the IEC binary prefix definitions, Philippe Mathieu-Daudé, 2018/06/25