传递“”的参数 1 使指针来自整数而不进行强制转换
passing argument 1 of ' 'makes pointer from integer without a cast
我目前正在从事 AUTOSAR 项目,因此生成的代码基于该特定软件,可能看起来有些奇怪。但是文件 First.c 是完整的 C。我的问题是关于访问存储在 C 中的指针变量中的值。
我有一个头文件 'header.h',它引用了一个函数,如下所示。此头文件进一步访问另一个文件中的单独函数。
header.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;
}
您应该传递正确的、类型转换正确的值
result = First_Element((uint32 *) &x);
最好重新考虑将 x 声明为有符号整数
int x;
您可能想更改以下内容
printf("The value in result is %d", &result);
到
printf("The value in result is %d", result);
我目前正在从事 AUTOSAR 项目,因此生成的代码基于该特定软件,可能看起来有些奇怪。但是文件 First.c 是完整的 C。我的问题是关于访问存储在 C 中的指针变量中的值。
我有一个头文件 'header.h',它引用了一个函数,如下所示。此头文件进一步访问另一个文件中的单独函数。
header.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;
}
您应该传递正确的、类型转换正确的值
result = First_Element((uint32 *) &x);
最好重新考虑将 x 声明为有符号整数
int x;
您可能想更改以下内容
printf("The value in result is %d", &result);
到
printf("The value in result is %d", result);