【发布时间】:2017-03-18 05:40:59
【问题描述】:
我有 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;
}
任何帮助都会对我有用
谢谢
【问题讨论】:
-
请查看问题中的代码:您有 3 种不同的结构类型:
struct config、struct data和struct config_data。这些应该是同一类型吗?请阅读minimal reproducible example。
标签: c data-structures struct shared-libraries