【发布时间】:2015-12-15 09:57:36
【问题描述】:
早安,
我拥有的是以下内容:
//Simulator.h
#ifndef SIMULATOR_H
#define SIMULATOR_H
inline void functionn1(void);
#endif
然后我有它的实现:
//Simulator.c
#include <stdio.h>
#include <stdlib.h>
#include "simulator.h"
inline void functionn1(void){printf("Functionn 1\n");}
最后是主程序:
//main.c
#include <stdio.h>
#include <stdlib.h>
#include "simulator.h"
int main(int argc, char** argv)
{
functionn1();
return (EXIT_SUCCESS);
}
它按预期工作,但在玩过之后我注意到:
- 当我从 Simulator.h 中注释掉函数原型时,它也可以工作
- 此外,当我注释掉函数原型并且故意不在 main.c 中包含 Simulator.h 时,该函数仍然有效。
为什么我做了上述两个步骤后它会起作用?这里到底在搞什么恶作剧?
【问题讨论】:
-
你试过用 -Wall 选项编译吗?它会给你
warning: implicit declaration of function -
如果您使用的是相当新的标准,例如 C99,它应该不再适用。当你写“functionn3”时,你的意思是
functionn1,不是吗? -
因为您实际上是在调用 functionn3() 。 functionn1 的定义无关紧要。
-
@LPs - 我正在使用 NetBeans IDE
-
@MOehm - 是的,我的意思是 functionn1 这是一个错字
标签: c function include header-files