2016-11-04 6 views
1

私はファイルの1つに2つの.cファイルを持っていますが、read_cfg(構造体)を呼び出して構造体内のデータを割り当てようとしますが、 "conflicting types"というエラーが発生します。 .hファイルread_cfg()と競合するタイプ

は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; 
} 

すべてのヘルプは

おかげ

+0

あなたの質問のコードを見直してください:構造体には 'struct config'、' struct data'、 'struct config_data'という3種類の構造体があります。これらは同じタイプであるはずですか? [mcve]をお読みください。 – user694733

答えて

1

にextern無効read_cfg(構造体); //エラー

エラーは、引数の型が一致していないためです。代わりにvoid read_cfg(struct config_data *)にする必要があります。

Btwの場合、関数のキーワードexternは必要ありません。デフォルトでは、関数には外部リンケージ(静的関数を除く)があります。

0

read_cfg()example.hで)機能とread_cfg()のあなたの定義(examplelib.cで)一致していないためにあなたの宣言私のために有用であろう。 example.hに宣言を変更 :

extern void read_cfg(struct config_data *cfg); 
関連する問題