uint32 InterruptLatency;
uint8 measurements[32];
char buf[256];
int kernelinterrupt time()
{
fscanf(fp,"%lu", InterruptLatency); // I am reading the data from kernel which is not shown here
measurements[17] = InterrupLatency;
buf = &measurements; // I am getting error here as below
// after storing it in buffer I am sending the data from but to another layer
}
错误:从类型uint8(*)[32]
分配char [256]类型时出现不兼容的类型有人可以帮我解决这个问题吗?
答案 0 :(得分:2)
在C中,您无法分配数组。你必须明确地复制内存。
可能你想这样做:
memcpy(buf, measurements, sizeof(measurements));
但是你没有透露你真正想做的事情。
PS:你的fscanf()
错了。它应该采用将保存读取值的变量的地址。
如果您使用uint32_t
,则应使用SCNu32
中的<inttypes.h>
规范,以确保不会破坏内容:
fscanf(fp,"%"SCNu32, &InterruptLatency);
答案 1 :(得分:0)
您正在尝试将指针值分配给数组。你不能这样做。
使用memcpy:
memcpy(buf, &measurements, sizeof(measurements));