我总是收到编译警告,但我不知道如何解决它:“%d”需要类型“诠释”的说法,但参数2的类型为“长unsigned int类型” [-Wformat =]
'%d' expects argument of type 'int', but argument 2 has type 'long unsigned int' [
程序运行正常,但我仍然得到编译警告:
/* Sizeof.c--Program to tell byte size of the C variable */
#include <stdio.h>
int main(void) {
printf("\nA Char is %d bytes", sizeof(char));
printf("\nAn int is %d bytes", sizeof(int));
printf("\nA short is %d bytes", sizeof(short));
printf("\nA long is %d bytes", sizeof(long));
printf("\nA long long is %d bytes\n", sizeof(long long));
printf("\nAn unsigned Char is %d bytes", sizeof(unsigned char));
printf("\nAn unsigned int is %d bytes", sizeof(unsigned int));
printf("\nAn unsigned short is %d bytes", sizeof(unsigned short));
printf("\nAn unsigned long is %d bytes", sizeof(unsigned long));
printf("\nAn unsigned long long is %d bytes\n",
sizeof(unsigned long long));
printf("\nfloat is %d bytes", sizeof(float));
printf("\nA double is %d bytes\n", sizeof(double));
printf("\nA long double is %d bytes\n", sizeof(long double));
return 0;
}
在Windows上的GCC 4.8.1中,出现错误:“printf'ing%zu时格式为”未知转换类型字符'z'。 –
@CzarekTomczak更新了答案,可能与此有关。 –
谢谢Shafik。不幸的是,这不是跨平台的。我必须将size_t转换为(unsigned long),以使代码可以在Linux和Windows上运行。在Linux上使用%Iu(I as Integer)时出现错误“format'%u'期望类型为'unsigned int'的参数”。 –