这是我工作时在linux环境下C++编译出现过的警告:
warning: format ?.d?.expects argument of type ?.nt?. but argument 3 has type ?.int64 {aka long long unsigned int}?.[-Wformat=]
除了以上分析的这种情况,还见到其他网友的分析中说到使用sacnf函数,输入的参数应该是变量地址而不是变量。
否则也会出现类似的错误警告。
例如
语句scanf("%s",name);中‘name’表示的是name数组首元素地址,无需取地址。
而语句scanf("%d",&size);中的size表示int变量,所以要在size前加&取地址。
warning: format ?.d?.expects argument of type ?.nt?. but argument 3 has type ?.int64 {aka long long unsigned int}?.[-Wformat=]
(void)query.create_sql("SELECT * FROM config_table ORDER BY pk_szName LIMIT %d, %d", nBeginInx, nCnt);
warning: format ?.d?.expects argument of type ?.nt?. but argument 3 has type ?.int64 {aka long long unsigned int}?.[-Wformat=]
(void)query.create_sql("SELECT * FROM config_table ORDER BY pk_szName LIMIT %d, %d", nBeginInx, nCnt);
根据提示和查阅代码,发现nBeginInx和nCnt变量类型的宏定义是Uint64,也就是 unsigned long long int 。
#ifndef Uint64 /**无符号64位整数*/
typedef unsigned long long Uint64;
#endif
代码中使用了%d的输入方式,与变量类型不符,修改代码为%llu(VS中还可以用%I64u)。编译后警告消失。
(同理 long long int 应该使用%lld)
除了以上分析的这种情况,还见到其他网友的分析中说到使用sacnf函数,输入的参数应该是变量地址而不是变量。
否则也会出现类似的错误警告。
例如
#include <stdio.h>
#include <string.h>
int main()
{
int size;
char name[40];
scanf("%s",name);
printf("%s\n",name);
printf("*************\n");
scanf("%d",&size);
printf("%d\n",size);
return 0;
}
语句scanf("%s",name);中‘name’表示的是name数组首元素地址,无需取地址。
而语句scanf("%d",&size);中的size表示int变量,所以要在size前加&取地址。