我有以下程序
#include <stdio.h>
int main(void)
{
unsigned short int length = 10;
printf("Enter length : ");
scanf("%u", &length);
printf("value is %u \n", length);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
其中编译时使用gcc filename.c发出以下警告(scanf()在行中).
warning: format ‘%u’ expects argument of type ‘unsigned int *’, but argument 2 has type ‘short unsigned int *’ [-Wformat]
然后我提到的C99 specification - 7.19.6 Formatted input/output functions,并使用长度调节剂(如当不明白正确的格式指定符short,long等)与unsigned用于int数据类型.
是%u正确的说明符unsigned short int吗?如果是这样,为什么我得到上述警告?!
编辑:大多数时候,我在尝试%uh,它仍在发出警告.