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