read_cfg()的冲突类型

时间:2016-11-04 11:42:30

标签: c data-structures struct shared-libraries

我有2个.c文件,在其中一个文件中我将尝试调用read_cfg(struct)来分配结构中的数据但是我收到.h文件中“冲突类型”的错误

example.c

#include<stdio.h>
#include"example.h"

struct config /structure
{
char data[10];
};

int main()
{
int n=0;
struct data d;
read_cfg(&d);   //function call
}

example.h文件

#ifndef EXAMPLE_H
#define EXAMPLE_H
extern void read_cfg(struct); //ERROR

examplelib.c

struct config  //structure
{
    char data[10];
};


void read_cfg(struct config_data *cfg) //function implementation 
{
struct config_data tmp;
strcpy(tmp.data,"helo");
cfg=&tmp;
}

任何帮助对我都有用

谢谢

2 个答案:

答案 0 :(得分:1)

  

extern void read_cfg(struct); //错误

错误是因为您的参数类型不匹配。它应该是void read_cfg(struct config_data *)

顺便说一下,函数不需要extern关键字 - 默认情况下,函数有外部链接(静态函数除外)。

答案 1 :(得分:0)

您对read_cfg()函数的声明(example.h)和read_cfg()examplelib.c中)的定义不匹配。 将example.h中的声明更改为:

extern void read_cfg(struct config_data *cfg);