我创建了一个取void*
的函数,并在get_value
函数和基于类型的操作中对该值进行类型转换后,向它传递了不同类型的值,例如float
、int
或double
.
Compiler error:
main.c:17:27:错误:"float"类型的操作数无法转换为指针类型
Question
When using an int
value, I can directly pass it with get_value((void *)10);
and then access the data by casting back with (int)
. But float
value gives the above compiler error. Why?
#include <stdio.h>
#include <stdint.h>
void get_value(void* data)
{
printf("Value %f \r\n", (float)data);
}
int main(void) {
float di = 10.10;
get_value((void *)di);
return 0;
}