Implicit declaration when using a function before it is defined in C, why can't the compiler figure this out?

Posted by rolls on Stack Overflow See other posts from Stack Overflow or by rolls
Published on 2011-01-10T09:40:49Z Indexed on 2011/01/10 9:53 UTC
Read the original article Hit count: 244

Filed under:
|
|
|

As the title says, I know what causes this error but I want to know why the compiler gives it in this circumstance.

Eg :

main.c

void test(){
    test1();
}

void test1(){
   ...
}

Would give an implicit declaration warning as the compiler would reach the call to test1() before it has read its declaration, I can see the obvious problems with this (not knowing return type etc), but why can't the compiler do a simple pass to get all function declarations, then compile the code removing these errors? It just seems so simple to do and I don't believe I've seen similar warnings in other languages.

Does anyone know if there is a specific purpose for this warning in this situation that I am overlooking?

© Stack Overflow or respective owner

Related posts about c

    Related posts about gcc