gpt4 book ai didi

c - 传递 ' ' 的参数 1 使指针来自整数而不进行强制转换

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

我目前正在从事一个 AUTOSAR 项目,因此生成的代码是基于该特定软件的,可能看起来有些奇怪。但是文件 First.c 是完整的 C。我的问题是关于访问存储在 C 中的指针变量中的值。

我有一个头文件“header.h”,它引用了一个函数,如下所示。此头文件进一步访问另一个文件中的单独函数。

标题.h

 static inline Std_ReturnType First_Element(uint32 *data){
return First_Element_Read(data);
}

此函数在 c 文件“First.c”中调用如下。

 int x;
int result;
void Func_call(void){

result = First_Element(x);
printf("The value in result is %d", &result);

return 0;
}

我只想将头文件中变量“data”的值访问到 C 文件中的 x 变量中。当我这样做时,我会收到警告

从不兼容的指针类型传递“First_Element”的参数 1。并且没有数据显示。有人可以在这里指出我的错误。

提前致谢!

最佳答案

First_Element 采用 uint32 * 类型的参数。

您可以使用 int 类型的参数调用它。

这些不匹配,所以它不起作用。很难看出您期望在这里发生什么,所以我真的不能建议修复。


更新:更正后的代码应该是:

 uint32 x;                                           /* <--- note type */
Std_ReturnType result; /* <--- note type */
void Func_call(void){

result = First_Element(&x); /* <--- added "&" */
printf("The value in result is %d", result);

return 0;
}

关于c - 传递 ' ' 的参数 1 使指针来自整数而不进行强制转换,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32690675/

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