GCC不会在编译器阶段抛出一个错误,当一个函数未被声明时 [英] GCC does not throw an error during the compiler stage when a function has not been forward declared

查看:134
本文介绍了GCC不会在编译器阶段抛出一个错误,当一个函数未被声明时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的,



我在我的目录中有3个文件。

main.c

  #include< stdio.h> 
int main(int a,int b,int c)
{
aprint();
bprint();

$ / code>

ac

  #include< stdio.h> 

void aprint()
{
printf(hey This is a.c);



bc

  #include< stdio.h> 
void bprint()
{
printf(This is b.c);
}

我还没有创建任何头文件。
我刚刚使用gcc main.c a.c b.c编译
我没有收到任何错误。我想知道发生了什么?
gcc只是假设在链接阶段一切都会好起来,为什么gcc在编译期间不会抛出错误?

解决方案

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


Ok,

I have 3 files in my directory.

main.c

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

a.c

#include <stdio.h>

void aprint()
{
    printf("hey This is a.c");
}

b.c

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

I haven't created any header files. I just compiled using "gcc main.c a.c b.c" I didn't get any error. I want to know what happened? Did gcc just assume everything is going to be okay in linking stages and why didn't gcc throw an error during compilation?

解决方案

Enable warnings using -Wall flag, hten you will see warning: Implicit call to function bprint() and Implicit call to function aprint(). It's is basically compiler recognizes this function during Linker stage and this does not give any error.

这篇关于GCC不会在编译器阶段抛出一个错误,当一个函数未被声明时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆