1

好的,

我的目录中有 3 个文件。

主程序

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

交流

#include <stdio.h>

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

公元前

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

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

4

3 回答 3

7

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

于 2013-07-09T07:47:19.647 回答
3

C89/90 版本的 C 语言不需要前向声明函数。C 语言的 C99 版本确实需要函数进行前向声明。您是在 C89/90 模式还是 C99 模式下编译代码?

请注意,即使在 C99 模式下,编译器也可能仅将真正的错误(即违反约束)报告为警告。如果您希望 GCC 在将约束违规报告为错误时变得更加严格,请使用-pedantic-errorsswitch 运行它。

于 2013-07-09T07:53:39.823 回答
2

我给你带来了你的警告:

notroot@ubuntu:~/qweqwe$ gcc main.c a.c b.c -Wall
main.c:2:5: warning: second argument of ‘main’ should be ‘char **’ [-Wmain]
main.c:2:5: warning: third argument of ‘main’ should probably be ‘char **’ [-Wmain]
main.c: In function ‘main’:
main.c:4:1: warning: implicit declaration of function ‘aprint’ [-Wimplicit-function-declaration]
main.c:5:1: warning: implicit declaration of function ‘bprint’ [-Wimplicit-function-declaration]
main.c:6:1: warning: control reaches end of non-void function [-Wreturn-type]
于 2013-07-09T07:50:31.330 回答