/* 类型长度 */
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
int main(int argc, char *argv[])
{
uint64_t a = 5;
printf("a = %d\n", a);
return EXIT_SUCCESS;
}
使用 %d
来打印 uint64_t
,编译时提示警告:
liyongjun@Box20:~/project/c/study$ make t=others/type_size
gcc others/type_size.c -o others/type_size.out -Wall
others/type_size.c: In function ‘main’:
others/type_size.c:20:18: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘uint64_t’ {aka ‘long unsigned int’} [-Wformat=]
20 | printf("a = %d\n", a);
| ~^ ~
| | |
| int uint64_t {aka long unsigned int}
| %ld
uint64_t {aka long unsigned int}
这句话一直没理解,昨天查了一下,
AKA,是一个网络流行词,是 “Also Known As” 的缩写,意思是又名、亦称、也被称为。当某人或某事有广为人知的别名时,可以用 AKA 来介绍。该词在 HIP-HOP 嘻哈文化中广为流行。
哦,意思是 uint64_t {又名 long unsigned int}
所以此处警告的完整意思是
others/type_size.c 文件 :第 20 行 :第 18 列 :警告 :格式 ‘%d’ 期望参数的类型是 ‘int’,但是参数 2 的类型是 ‘uint64_t’ (即 ‘long unsigned int’)
修改很简单,按照提示,将 %d
改成 %ld
。