我有以下檔案:
swaps.c:
#include "swaps.h"
#include "./poolutils.h"
double someFunction(struct Pool pools[]){
//do some stuff
}
int main(){
struct Pool pool1 = {"A","C",3.0,9000.0,0.0};
struct Pool pool2 = {"B","D",20.0,20000,0.0};
struct Pool pools[N];
pools[0] = pool1;
pools[1] = pool2;
double a = someFunction(pools);
}
swaps.h有簽名someFunctionpoolutils.c有一些功能poolutils.h:
#ifndef _POOLUTILS_H
#define _POOLUTILS_H
struct Pool {
char *token1;
char *token2;
double reserve1;
double reserve2;
double fee;
};
//signatures of poolutils.c functions
#endif
編譯(gcc -c swaps.c poolutils.c)時,我收到以下錯誤:
In file included from swaps.c:1:
swaps.h:4:44: error: array type has incomplete element type ‘struct Pool’
4 | double someFunction(struct Pool pools[]);
現在,我確實包含了struct Pool定義的標題,所以swaps.c應該知道它,但我知道不知何故swaps.h,我怎樣才能讓它知道外部定義?
(gcc 版本 10.2.1 20210110 (Debian 10.2.1-6))
uj5u.com熱心網友回復:
只需添加
#include "./poolutils.h"
swaps.h如果swaps.h需要Pool結構定義,您也可以。
由于您已盡職盡責地將包含保護放入 中poolutils.h,因此您可以在單個編譯單元中多次使用標頭。
或者,交換包含的順序;這里的效果是一樣的。
#include "./poolutils.h"
#include "swaps.h"
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/477488.html
上一篇:組合陣列的相似元素
