首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C语言 >

求解释~ gcc编译不过?解决方法

2012-10-10 
求解释~ gcc编译不过??test.hC/C++ code#ifndef TEST_H#define TEST_H#define NODE struct snodeextern vo

求解释~ gcc编译不过??
test.h

C/C++ code
#ifndef TEST_H#define TEST_H#define NODE struct snodeextern void func(NODE* node);#endif


C/C++ code
#include "test.h"struct snode{};void func(NODE* node){}


gcc -c test.c

错误:
test.c:4: error: conflicting types for ‘func’
test.h:6: note: previous declaration of ‘func’ was here


[解决办法]
你需要把struct snode{};放到test.h中。
[解决办法]
重复定义了func(NODE* node)。你在test.h里申明了该函数,又在test.c里申明
[解决办法]
链接的时候出问题了吧。找不到FUNC这个函数。。
[解决办法]
声明的函数依赖Node,但你没有在函数之前声明Node结构体。

而且你还自以为聪明的在源文件函数定义之前放了一个结构体定义,殊不知你包含的头文件里的函数声明无法在之前的出现的代码中找到结构体的声明.
[解决办法]
楼主,改学C++吧,C++才有类型前置声明。
[解决办法]
C也有前置声明.
[解决办法]
C/C++ code
#include <stdio.h>#include <stdlib.h>#include <string.h>struct node_st;void func(struct node_st*);int main(int argc, char* const argv[]) {        func(NULL);        return 0;}struct node_st {        int n;};void func(struct node_st *node) {        if (node) {                printf("%d\n", node->n);        }} 

热点排行