分页: 1 / 1

conflicting types for这个警告是什么

发表于 : 2008-12-02 9:40
ningxinleng
今天在看C primer的时候照着书上写了一个小程序,然后用gcc编译的时候有这个警告,可是我不觉得有这个警告,不知道是什么原因,大家帮我看一下。源代码:
1 #include<stdio.h>
2
3 int main(int argc,char **argv)
4 {
5 printf("starting:\n");
6 one_three();
7 printf("end!\n");
8
9 return 0;
10 }
11
12 void one_three(void)
13 {
14 printf("one\n");
15 two();
16 printf("three\n");
17
18 }
19
20 void two(void)
21 {
22 printf("two\n");
23 }
警告如下,
show.c:12: warning: conflicting types for ‘one_three’
show.c:6: warning: previous implicit declaration of ‘one_three’ was here
show.c:20: warning: conflicting types for ‘two’
show.c:15: warning: previous implicit declaration of ‘two’ was here
但是如果我把void类型换成int类型后编译就不会有这个警告了,难道在gcc不支持void返回值么?

Re: conflicting types for这个警告是什么

发表于 : 2008-12-02 19:05
xyywll
lz 还生活在远古时代,估计是看的某些书。。
看看较新的书,还可以看看 C99 国际标准

Re: conflicting types for这个警告是什么

发表于 : 2008-12-03 11:53
ningxinleng
我想知道为什么那里会出现那个警告

Re: conflicting types for这个警告是什么

发表于 : 2008-12-03 11:57
HuntXu
函数在后面定义先要在前面声明吧...
否则gcc默认当成int了?
把void two(void)和void one_three(void)加到main()前边?

Re: conflicting types for这个警告是什么

发表于 : 2008-12-03 12:06
ningxinleng
恩,确实是这个原因,谢谢了

Re: conflicting types for这个警告是什么

发表于 : 2010-11-11 12:00
liuzhiwei
这是个很简单的错误,就是你在一个函数定义之前就去引用它了,这在C语言里是不允许的,尽管void 类型的可以,但是还会提示警告,而其它返回类型的则直接错误。 不想把函数放在前面书写的,可以将其函数名统一写在main() 前边。 如 void one_three(); void two();void three();
int main(){...} void one_three(){.....};.....

Re: conflicting types for这个警告是什么

发表于 : 2011-07-30 12:25
dncomputer
在cache.h中定义函数:
unsigned int /* latency of access in cycles */
cache_access(struct cache_t *cp, /* cache to access */
enum mem_cmd cmd, /* access type, Read or Write */
md_addr_t addr, /* address of access */
md_addr_t fetch_pc, /*pc value*/
struct fu_cache_pspec_t *cache_pspec, /*cache power */
void *vp, /* ptr to buffer for input/output */
int nbytes, /* number of bytes to access */
tick_t now, /* time of access */
byte_t **udata, /* for return of user data ptr */
md_addr_t *repl_addr); /* for address of replaced block */

现在在cache.c中实现:
unsigned int /* latency of access in cycles */
cache_access(struct cache_t *cp, /* cache to access */
enum mem_cmd cmd, /* access type, Read or Write */
md_addr_t addr, /* address of access */
md_addr_t fetch_pc, /*pc value*/
struct fu_cache_pspec_t *cache_pspec, /*cache power */
void *vp, /* ptr to buffer for input/output */
int nbytes, /* number of bytes to access */
tick_t now, /* time of access */
byte_t **udata, /* for return of user data ptr */
md_addr_t *repl_addr) /* for address of replaced block */
{
.
......
}
报错:
cache.c:605: conflicting types for `cache_access'
cache.h:332: previous declaration of `cache_access'
搞不明白,请各位大虾指点一下,万分感谢!!