gpt4 book ai didi

c - 头文件中的结构在源文件中产生错误

转载 作者:太空宇宙 更新时间:2023-11-04 03:16:28 24 4
gpt4 key购买 nike

我在 capi_utils.h 中定义了一个结构,如下所示:

#ifndef _CAPI_UTILS_H_
# define _CAPI_UTILS_H_

...

struct ScalarVariable{
char name[63];
float value;
uint8_T DataID;
char type[50];
};

...
#endif

capi_utils.c 中,我尝试创建一个变量来保存这样的结构

struct ScalarVariable sVariable;

只有当我尝试在结构中设置值时才会产生错误,如下所示:

sVariable.name = paramName;

错误信息是:

capi_utils.c:27: error: invalid use of undefined type `struct ScalarVariable'

我做错了什么?

编辑 1:

我只需要包含 capi_utils.h。不认为我必须这样做,因为出于某种原因我理解了不同的源文件和 header 。

编辑 2:

澄清一下,我什至在尝试设置 DataID 时遇到错误,而不仅仅是数组。

void GetValueFromAdress(const char_T*  paramName,
void* paramAddress,
uint8_T slDataID,
unsigned short isComplex,
uint_T* actualDims,
uint_T numDims,
real_T slope,
real_T bias) {

sVariable.DataID = slDataID;

}

会产生error: invalid use of undefined type 'struct ScalarVariable'

最佳答案

cape_utlis.c中,您需要包含头文件,如下所示:

#include cape_utlis.h

此外,改变这个:

sVariable.name = paramName;

为此:

strcpy(sVariable.name, paramName)

为了在 C 中复制以 NULL 结尾的字符串,您可以使用函数 strcpy ,而不是赋值运算符。

关于c - 头文件中的结构在源文件中产生错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51025626/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com