This is the mail archive of the cygwin mailing list for the Cygwin project.
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |
Other format: | [Raw text] |
On 05/24/2017 06:36 PM, Steven Penny wrote: > On Wed, 24 May 2017 07:33:27, Eric Blake wrote: >> Buggy. size_t should be printed with %zi, not %i (since size_t and int >> are not necessarily the same type). > > Aren’t both wrong? By definition %i is a signed integer, and size_t is > unsigned. > So %zu Correct. Newer gcc's -Wformat-signedness will flag the discrepency. > or %llu would be more correct: NO. Do NOT use %llu with size_t, because it is not portable to 32-bit platforms. That's WHY %zu exists. > They all seem to do the job though: Yes. On all modern platforms, you can freely mix signed and unsigned integers and get correct (when the number is positive and does not exceed the signed maximum) or at least sane results (2s complement counterpart for all other values) regardless of which direction you mess with incorrect signedness. However, such behavior is technically not required by the C standard, which is why gcc added -Wformat-signedness. -- Eric Blake, Principal Software Engineer Red Hat, Inc. +1-919-301-3266 Virtualization: qemu.org | libvirt.org
Attachment:
signature.asc
Description: OpenPGP digital signature
Index Nav: | [Date Index] [Subject Index] [Author Index] [Thread Index] | |
---|---|---|
Message Nav: | [Date Prev] [Date Next] | [Thread Prev] [Thread Next] |