今天遇到个挺坑爹的事情;犯了一个很蠢的错误:
liuzemei@ubuntu:~/Documents/three/day01/tmath$ gcc test.c
test.c: In function ‘main’:
test.c:6:20: warning: implicit declaration of function ‘t_add’ [-Wimplicit-function-declaration]
printf("x+y=%d\n",t_add(x,y));
^
test.c:7:20: warning: implicit declaration of function ‘t_sub’ [-Wimplicit-function-declaration]
printf("x-y=%d\n",t_sub(x,y));
^
test.c:8:20: warning: implicit declaration of function ‘t_mul’ [-Wimplicit-function-declaration]
printf("x*y=%d\n",t_mul(x,y));
^
test.c:9:20: warning: implicit declaration of function ‘t_div’ [-Wimplicit-function-declaration]
printf("x/y=%d\n",t_div(x,y));
提示信息:
warning: implicit declaration of function
原来是头文件里的信息出问题了。
头文件卫士:的#ifndef写成了的#ifdef
结果就报错了。这里报的错误是,隐式声明函数。就是说我函数没有声明,
原因是在头文件里,的#ifdef,就直接把头文件跳过了。
编译的时候就报警告。但这里好像还是读取到了这几个函数。
有点奇怪。为什么我都把头文件的所有函数声明跳过了,然后就变成隐式声明了呢?
是不是因为,我在链接的时候,自动读取了其他程序文件里的函数,然后这个里边都是包含了头文件的,虽然头文件里没有显式声明,其他文件里的函数定义就直接在主函数里默认就隐式声明函数了?