警告:传递‘memcpy’的参数 2 使指针来自整数而不进行强制转换[默认启用]
uint8 InterruptLatency;
char buf[256];
int kernelinterrupt time()
{
fscanf(fp, "%"SCNu8"\n", &InterruptLatency); // I am reading the data from kernel which is not shown here
memcpy(buf, InterruptLatency, sizeof(InterruptLatency)); // warning here as above
// after storing it in buffer I am sending the data from but to another layer
}
最佳答案
memcpy()
函数需要两个指针,但 InterruptLatency
是一个 8 位整数。
解决方法是取变量的地址:
memcpy(buf, &InterruptLatency, sizeof InterruptLatency);
^
|
address-of
operator
请注意,在获取实际对象的大小时,sizeof
不需要括号。这是因为 sizeof
不是函数。
另请注意,像这样使用memcpy()
将单个字节复制到字节数组中永远不会发生在“真正的”C 代码中。我会这样做:
buf[0] = InterruptLatency;
关于c - 如何解决c警告:pointer from integer without a cast?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23337710/