On 09/10/2013 10:07 AM, Ralf Junker wrote:
On 09.10.2013 15:50, Eric Minbiole wrote:

With this change, tests pass again:

     #if sizeof(p->nRow) == sizeof(long long)
     sqlite3_snprintf(24, zRet, "%lld", p->nRow);
     #elseif sizeof(p->Row) = sizeof(long)
     sqlite3_snprintf(24, zRet, "%ld", p->nRow);
     #else
     sqlite3_snprintf(24, zRet, "%d", p->nRow);
     #endif

Slightly off-topic, but I didn't think that sizeof() could be used as part
of a preprocessor directive?  (I.e., that #if sizeof(x) doesn't work as
intended, or at least not portably.)

This is more portable:

    #ifdef SQLITE_64BIT_STATS
    sqlite3_snprintf(24, zRet, "%lld", p->nRow);
    #else
    sqlite3_snprintf(24, zRet, "%d", p->nRow);
    #endif
Actually, some machines define 64-bit ints as long, and passing them to printf with %lld triggers compiler warnings [1]. Technically the portable way is to make sure the int is a [u]int64_t from <inttypes.h> and then use the (awful and painful) printf modifiers from the same header (PRIu64 et al). An easier workaround is to define the int as size_t and then use %zd in printf... but I think %zd is a GNU extension.

[1] in that particular case the warning is harmless, but it's a bad idea to train oneself to ignore printf warnings about variable sizes, lest problems like the one we're discussing arise.

Ryan

_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to