Warning using sprintf("%llu", uint64_t) on AMD64

Tim Prince tprince@computer.org
Fri Aug 24 04:58:00 GMT 2007


tabris wrote:
> routines.cpp: In function 'const std::string uint64toString(const
> uint64_t&)':
> routines.cpp:87: warning: format '%llu' expects type 'long long unsigned
> int', but argument 4 has type 'long unsigned int'
> routines.cpp:87: warning: format '%llu' expects type 'long long unsigned
> int', but argument 4 has type 'long unsigned int'
> routines.cpp: In function 'const std::string int64toString(const int64_t&)':
> routines.cpp:93: warning: format '%lld' expects type 'long long int',
> but argument 4 has type 'long int'
> routines.cpp:93: warning: format '%lld' expects type 'long long int',
> but argument 4 has type 'long int'
>
>
>     Now, in fact I am not using 'long long unsigned int' nor 'long
> unsigned int' but rather uint64_t and int64_t
>
> From stdint.h
>
> # if __WORDSIZE == 64
> typedef long int                int64_t;
> # else
> __extension__
> typedef long long int           int64_t;
> # endif
>
>     Further I've verified that long int is 64bits on AMD64, and long
> long is 64bits on AMD64.
>
>     These warnings feel bogus, the only thing I can think of is that on
> some platforms, 'long long' might be 128-bit. But then then suggests the
> question of how do I do an sprintf portably with 64-bit ints?
>     Is there a [good] reason for this warning, and what should I do
> about it (even if the reason is bad, I need to silence the warning)
>   
In my state of ignorance of good style for mixed C and C++, using a 
(long long) or (unsigned long long) cast to silence the warning seems 
reasonable (except that it could silence a warning about a serious 
error).  I've seen several times the argument that gcc or g++ should 
give such warnings for general portability reasons, even when there 
can't be a problem on a given target.



More information about the Gcc-help mailing list