Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is implicit function declaration legal in C89?

Consider this C program:

int main()
{
    puts("Hello world!");
    return 0;
}

This compiles and runs fine and as far as I understand, is legal C89. However, I'm not 100% sure about that. Compiling in C99 mode with clang informs me that implicit declaration of function 'puts' is invalid in C99 (which makes me think that the C standard must have changed in C99 to make implicit function declaration illegal, which is what I'm trying to confirm).

Is implicit function declaration legal in C89? (even if it's a bad idea to do it (unless your in an obfuscated C code challenge))

like image 923
Cornstalks Avatar asked Sep 09 '25 12:09

Cornstalks


1 Answers

Is implicit function declaration legal in C89?

Yes. From section 3.3.2.2:

If the expression that precedes the parenthesized argument list in a function call consists solely of an identifier, and if no declaration is visible for this identifier, the identifier is implicitly declared exactly as if, in the innermost block containing the function call, the declaration

    extern int  identifier();

appeared.

like image 120
Oliver Charlesworth Avatar answered Sep 11 '25 02:09

Oliver Charlesworth