int64_t 的格式化打印

ALOGD("transfer gps nmea get parameters: gpsUtcTimestamp=%ld, nmea=%s, length=%d",

                                gpsUtcTimestamp, nmea_tmp, length);

报错:

 error: format specifies type 'long' but the argument has type 'int64_t' (aka 'long long') [-Werror,-Wformat]


所以在32位机器上就应该是%lld, 在64位机器上应该是%ld ,

那么如何统一写呢。

如何判断系统是32还是64位的呢:

代码中:

#if __WORDSIZE == 64

#endif

 

脚本中:

if [ `getconf LONG_BIT` -eq 64 ];then

64位处理逻辑

else

32位处理逻辑

fi


不过有更好办法:

参考:http://blog.163.com/hevensun@126/blog/static/20153363201311257829882/

#include

    ALOGD("transfer gps nmea get parameters: gpsUtcTimestamp=%"PRId64", nmea=%s, length=%d",

                                gpsUtcTimestamp, nmea_tmp, length);

报错:

error: invalid suffix on literal; C++11 requires a space between literal and identifier [-Wreserved-user-defined-literal]

                        ALOGD("transfer gps nmea get parameters: gpsUtcTimestamp=%"PRId64", nmea=%s, length=%d",


==》 PRId64前面应该还有个空格,不要忘记。这样就好了。

ALOGD("transfer gps nmea get parameters: gpsUtcTimestamp=%" PRId64", nmea=%s, length=%d",
                                gpsUtcTimestamp, nmea_tmp, length);



你可能感兴趣的:(android)