当函数未被前向声明时,GCC在编译阶段不会抛出错误

Nik*_*hil 1 c unix gcc

好,

我的目录中有3个文件.

main.c中

#include <stdio.h>
int main(int a, int b, int c)
{
    aprint();
    bprint();
}
Run Code Online (Sandbox Code Playgroud)

AC

#include <stdio.h>

void aprint()
{
    printf("hey This is a.c");
}
Run Code Online (Sandbox Code Playgroud)

公元前

#include <stdio.h>
void bprint()
{
   printf("This is b.c");
}
Run Code Online (Sandbox Code Playgroud)

我还没有创建任何头文件.我刚刚编译使用"gcc main.c ac bc"我没有得到任何错误.我想知道发生了什么?gcc是否只是假设链接阶段的一切都没问题,为什么gcc在编译期间没有抛出错误?

Ish*_*eet 7

使用-Wall标志启用警告,您将看到警告:对函数bprint()的隐式调用和对函数aprint()的隐式调用.它基本上是编译器在链接器阶段识别此函数,这不会给出任何错误.