Does the following program invoke Undefined Behaviour
in C?
int main()
{
printf("Printf asking: Where is my declaration ?");
}
In the above program there is an implicit declaration of printf()
, so is the above code fully standard compliant or it just has some implementation specific behaviour?
Yes it does. Not having a declaration in scope is UB.
Also, note that falling off main is okay in C99 (i.e. semantically equivalent to a
return 0;
). For pre-C99 compliant compilers you need a return statement where the return type of the main function is a type compatible withint
.