On Sun, Jan 06, 2019 at 03:22:50AM +0000, Adam Steen wrote:
> Hi All
>
> I have a question about string (printf) formatting.
>
> I have a variable
>
> 'uint64_t freq'
>
> which is printed with
>
> 'log(DEBUG, "Solo5: clock_init(): freq=%lu\n", freq);'
>
> but am getting the following error
>
> '
> error: format specifies type 'unsigned long' but the argument has type
> 'uint64_t' (aka 'unsigned long long') [-Werror,-Wformat]
> freq);
> ^~~~~~~~
> 1 error generated.
> '
>
> The easy fix is to change the format to '%llu', but this brakes FreeBSD and
> Linux. Am i missing something or should i be investigating the log
> implementation?
>
>
> Cheers
> Adam
If you want to print an int type from <stdint.h>, use the printf()
format defined for that type in <inttypes.h>:
uint64_t freq;
/* ... */
printf("freq is %" PRIu64 " Hz\n", freq);
See e.g. https://en.cppreference.com/w/c/types/integer
Cheers,
--
Andreas Kusalananda Kähäri,
National Bioinformatics Infrastructure Sweden (NBIS),
Uppsala University, Sweden.