D
Dan Pop
In said:Ok, I get the point. But if you were asked this question in a
technical test with 4 options
a) error during compilation
b) goes into an infinite loop
c) 5 6.000000 6 5.000000
d) 5 6.000000 0 0.000000
What would you choose?
It depends on the date the question was asked ;-)
Before the release of C89, the answer would be a) or b): the macro
replacement causes infinite recursion, which could result in either an
error message or the preprocessor going into an infinite loop:
mentor:~/tmp 12> gcc -traditional -E test.c
test.c:6: macro or `#include' recursion too deep
test.c:7: macro or `#include' recursion too deep
test.c:8: macro or `#include' recursion too deep
test.c:8: macro or `#include' recursion too deep
test.c:9: macro or `#include' recursion too deep
test.c:9: macro or `#include' recursion too deep
# 1 "test.c"
main()
{
int =5;
float =6.0;
printf("\n %d %f",,);
printf(" %d %f",,);
}
In standard C, the macro definitions are harmless, the nested macro
replacement being stopped when the original macro name comes up again,
so by the time A becomes A again, the replacement is stopped. But,
in standard C, calling printf without a prototype in scope and passing
an argument of the wrong type to printf results in undefined behaviour,
which includes *all* the above listed options, as well as an infinity
of others.
And a C99 compiler would also object to the definition of the main
function, which requires an explicit return type.
However, the program has the look and feel of a pre-ANSI C program...
Dan