On Tue, Nov 01, 2011 at 10:15:09AM -0700, Chris Hostetter wrote:
> 3) A few misc warnings popped up during C compilation...
Grr. These are annoying.
> /home/hossman/tmp/lucy-rc/apache-lucy-incubating-0.2.2/perl/Lucy-0.2.2/core/Lucy/Object/CharBuf.c:259:
> warning: format ‘%lld’ expects type ‘long long int’, but argument 3 has type
> ‘int64_t’
The compiler is crying wolf.
It's not important to distinguish between a signed 64-bit integer type named
"long long int" and another signed 64-bit integer type named "int64_t" when
passing arguments to *printf. The compiler ought to be smart enough to figure
out that those are equivalent.
> /home/hossman/tmp/lucy-rc/apache-lucy-incubating-0.2.2/perl/Lucy-0.2.2/core/Lucy/Util/Memory.c:28:
> warning: format ‘%llu’ expects type ‘long long unsigned int’, but argument 3
> has type ‘size_t’
Here's the line in question:
fprintf(stderr, "Can't malloc %" U64P " bytes.\n", (uint64_t)count);
The variable "count" is indeed a "size_t". However, it is specifically being
cast to a uint64_t so that fprintf will get a 64-bit integer to go with that
64-bit format string specifier regardless of whether size_t is 32 bits or
64 bits.
Thanks for pointing these warnings out, Hoss. I would like to silence them,
but it's hard to do that portably -- for instance, we can't cast to "long long
int" because it's not there on all systems.
For the second case, we could theoretically create a temporary uint64_t
variable and stop the compiler from complaining about size_t. But I'm almost
positive the compiler would then whine about a uint64_t not being the "long
long unsigned int" it wants to see paired with "%llu".
Marvin Humphrey