История изменений
Исправление splinter, (текущая версия) :
#define MIN(a,b) (a < b) ? a : b
#define A 123
#define B 11.1111
#define C 999999999
int main()
{
printf("sizeof : %d\n",sizeof(A));
printf("sizeof : %d\n",sizeof(B));
printf("sizeof : %d\n",sizeof(C));
printf("MIN : %d\n", MIN(A, B));
printf("MIN : %d\n", MIN((C / 45), (A * 18.0)));
return 0;
}
ex1.c:7:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(A));
~^
%ld
ex1.c:8:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(B));
~^
%ld
ex1.c:9:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(C));
~^
%ld
ex1.c:10:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
printf("MIN : %d\n", MIN(A, B));
~^
%f
ex1.c:11:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
printf("MIN : %d\n", MIN((C / 45), (A * 18.0)));
sizeof : 4
sizeof : 8
sizeof : 4
MIN : 330175072
MIN : 330175072
Исходная версия splinter, :
Специально ужасный пример :-)
#define MIN(a,b) (a < b) ? b : a
#define A 123
#define B 11.1111
#define C 999999999
int main()
{
printf("sizeof : %d\n",sizeof(A));
printf("sizeof : %d\n",sizeof(B));
printf("sizeof : %d\n",sizeof(C));
printf("MIN : %d\n", MIN(A, B));
printf("MIN : %d\n", MIN((C / 45), (A * 18.0)));
return 0;
}
ex1.c:7:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(A));
~^
%ld
ex1.c:8:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(B));
~^
%ld
ex1.c:9:20: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long unsigned int’ [-Wformat=]
printf("sizeof : %d\n",sizeof(C));
~^
%ld
ex1.c:10:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
printf("MIN : %d\n", MIN(A, B));
~^
%f
ex1.c:11:17: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘double’ [-Wformat=]
printf("MIN : %d\n", MIN((C / 45), (A * 18.0)));
sizeof : 4
sizeof : 8
sizeof : 4
MIN : 330175072
MIN : 330175072