[webkit-dev] Reminder: be careful when printing sized integer types

Yusuke SUZUKI utatane.tea at gmail.com
Thu May 11 18:18:57 PDT 2017


Or, alternative way is casting the value to `unsigned long long` and always
using %llu for uint64_t.

uint64_t value = ...;
printf("%llu", (unsigned long long)value);

Regards,
Yusuke Suzuki

On Wed, May 10, 2017 at 4:07 AM, Michael Catanzaro <mcatanzaro at igalia.com>
wrote:

> Hi,
>
> This is just a reminder to avoid a case that occasionally causes warnings
> for GTK+. On Mac, uint64_t is (I assume) a typedef for unsigned long long.
> But on Linux 86_64 it's a typedef for unsigned long. This means they have
> to be printed differently. Using "%llu" to print a uint64_t (presumably)
> works on Mac, but it causes compiler warnings on Linux. The right way is
> unfortunately to use "%" PRIu64, which expands to "%llu" on Mac and "%lu"
> on Linux. There are variants on these macros for many different integer
> types: http://en.cppreference.com/w/cpp/types/integer
>
> It's verbose, but helps us avoid warnings. And since it's declared in
> stdint.h/cstdint, if you're using uint64_t then it's already available.
>
> Thanks,
>
> Michael
>
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20170512/c723a098/attachment.html>


More information about the webkit-dev mailing list