On Jan 23, 2012 05:43:06 PST, Richard Hipp wrote:
On Mon, Jan 23, 2012 at 12:49 AM, Tommy wrote:
To whom it may concern,
After bringing the SQLite amalgamation into my library and compiling,
Apple Xcode produced the following warning:
sqlite3.c:27620:32:{27620:32-27620:45}{27620:30-27620:31}: warning:
implicit conversion from 'long long' to 'long' changes value from
9223372036854775807 to -1 [-Wconstant-conversion,3]
The code in question is:
#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
I hope this helps. If at all possible, I would appreciate learning
what the issue is, as I'm new to C.
I don't know why this warning is coming up. We don't use Xcode,
preferring
instead to use ordinary text editors (vi and emacs) and invoke the
compiler
directly. And we don't get the above warning on Macs (having tried
it on
Leopard, SnowLeopard, and Lion).
Using the sqlite-amalgamation-3071000,
here's the full clang warning which is considerably more helpful:
sqlite3.c:27620:32: warning: implicit conversion from 'long long' to
'long' changes value from 9223372036854775807 to -1 [-Wconstant-
conversion]
mask = (sizeof(long)==8) ? LARGEST_INT64 : 0x7fffffff;
~ ^~~~~~~~~~~~~
sqlite3.c:7946:25: note: expanded from:
#define LARGEST_INT64 (0xffffffff|(((i64)0x7fffffff)<<32))
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1 warning generated.
On line 27615, mask is defined to be of type long, so the #define is
not the problem, the assignment is. It's a pity the clang optimizer
didn't kick in first and eliminate the conditional operator before
spewing the warning since the "sizeof(long)==8" is a compile-time
constant.
If you compile the amalgamation with the gcc option -Wshorten-64-to-32
(you need Apple's gcc for this option) then you get:
sqlite3.c: In function 'afpLock':
sqlite3.c:27620: warning: implicit conversion shortens 64-bit value
into a 32-bit value
sqlite3.c: In function 'Unlock':
sqlite3.c:27764: warning: implicit conversion shortens 64-bit value
into a 32-bit value
Line 27764 is:
int sharedLockByte = SHARED_FIRST+pInode->sharedByte;
And sharedByte is indeed a long long.
So changing the first line to:
mask = (sizeof(long)==8) ? (long)LARGEST_INT64 : 0x7fffffff;
and the second to:
int sharedLockByte = (int)(SHARED_FIRST+pInode->sharedByte);
gets rid of the warnings both from clang and from apple's gcc with the
-Wshorten-64-to-32 warning enabled. That second one is a bit
concerning though if sqlite should ever be compiled on a system where
sizeof(int) < 4 and __APPLE__ is defined and
SQLITE_ENABLE_LOCKING_STYLE is set since SHARED_FIRST requires 32
bits. Presumably that can't happen although I wonder about Mac OS
Classic perhaps if anyone's still using that it might be an issue there.
clang (clang.llvm.org) is widely available on Linux (Ubuntu package
since 10.04) and *BSD (FreeBSD includes clang by default starting with
version 9.0).
Kyle
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users