sv_info.sv_list.size() 这个是c++的vector, 定义是这样的std::vector<ParcelableGpsSvInfo> sv_list; 格式化打印是这样的sv_list.size=%ud , 然后就这样报错拉:::
gateway.cpp:134:109: error: format specifies type 'unsigned int' but the argument has type 'size_type' (aka 'unsigned long') [-Werror,-Wformat]
sv_info.size, sv_info.num_svs, sv_info.ephemeris_mask, sv_info.almanac_mask, sv_info.used_in_fix_mask, sv_info.sv_list.size());
^~~~~~~~~~~~~~~~~~~~~~
比较奇怪,不知道是啥原因啊。。。
然后打印换成sv_list.size=%lu, 报错就相反了::::
gateway.cpp:134:109: error: format specifies type 'unsigned long' but the argument has type 'size_type' (aka 'unsigned int') [-Werror,-Wformat]
sv_info.size, sv_info.num_svs, sv_info.ephemeris_mask, sv_info.almanac_mask, sv_info.used_in_fix_mask, sv_info.sv_list.size());
gateway.cpp:134:109: error: format specifies type 'unsigned int' but the argument has type 'size_type' (aka 'unsigned long') [-Werror,-Wformat]
sv_info.size, sv_info.num_svs, sv_info.ephemeris_mask, sv_info.almanac_mask, sv_info.used_in_fix_mask, sv_info.sv_list.size());
^~~~~~~~~~~~~~~~~~~~~~
比较奇怪,不知道是啥原因啊。。。
然后打印换成sv_list.size=%lu, 报错就相反了::::
gateway.cpp:134:109: error: format specifies type 'unsigned long' but the argument has type 'size_type' (aka 'unsigned int') [-Werror,-Wformat]
sv_info.size, sv_info.num_svs, sv_info.ephemeris_mask, sv_info.almanac_mask, sv_info.used_in_fix_mask, sv_info.sv_list.size());
==》size()的结果返回的是size_t, 所以应该使用 %zd
%zu用来输出size_t 类型
size_t和int的区别是 size_t是一些C/C++标准在stddef.h中定义的。这个类型足以用来表示对象的大小。 size_t的真实类型与操作系统有关,在32位架构中被普遍定义为: typedef unsigned int size_t; 而在63位架构中被定义为: typedef unsigned long size_t; size_t在32位架构上是4字节,在64位架构上是8字节,在不同架构上进行编译时需要注意这个问题 int在不同架构下都是4字节 int是带符号书,size_t是无符号数