如何通过参考随附的库函数传递结构? 我的C程序使用动态分配的结构阵列。我正在尝试将指针传递给数组的特定成员到包含库中的函数,并且我正在获取编译器...

问题描述 投票:0回答:1
Main.c

中代码库

//.... #include "BMS.c" //.... struct BMS_dev{ // specific to each battery pack char err[16]; //..... bool b_lim ; }; //.... // other constants & variables declared //.... int main(){ // setup and configure char b = 0; char dev; //...... //more code //.... b = hello_all(); struct BMS_dev pack[b]; // Array of structures declared here, b could be 1 ,2, 3, 4 //...... for (dev=0;dev<b;dev++){ // main loop of program cycles through each device, 0 .. b char h = 0; id[dev] = 0; //..... v_cell_d(&pack[dev]); // function v_cell_d is called, passing reference to pack[b] // ... //rest of main.//

BMS.c

该程序的编译为:

bool v_cell_d(struct BMS_dev *pp){
   
    //vc_del = 0;
    pp->vc_max = 0;
    pp->vc_min = 4;
    float lim_low = 2.75 ;//#V
    float lim_high = 3.58 ;//#V
    pp->b_lim = false;
    //......
    return(pp->b_lim)  ;  
  }

计算机错误:

gcc -g main.c -l sqlite3 -o Max10 -lm

第一个错误是由于试图告诉编译器

In file included from main.c:14:
BMS.c:13:15: warning: useless storage class specifier in empty declaration
   13 | extern struct BMS_dev;
      |               ^~~~~~~
BMS.c: In function ‘v_cell_d’:
BMS.c:157:7: error: invalid use of undefined typestruct BMS_dev157 |     pp->vc_max = 0;
      |       ^~
BMS.c:158:7: error: invalid use of undefined typestruct BMS_dev158 |     pp->vc_min = 4;
      |       ^~
BMS.c:161:7: error: invalid use of undefined typestruct BMS_dev161 |     pp->b_lim = false;
的结构在其他地方(在

*pp

)中声明;没有此,它假设我试图在函数变量列表中声明结构。

我如何做这项工作?
    

没有您的文件,只有
main.c
文件。您用于构建程序的命令应指定所有
#include

文件,然后将它们链接在一起以生成

.c

c structure
1个回答
0
投票
就是说,

.h

的定义不属于
.c
,它应该在一个单独的
.exe
文件中,然后可以在
struct BMS_dev
main.c
/
中。 .h

.

	
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.