不兼容的C型错误?

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]类型时出现不兼容的类型

有人可以帮我解决这个问题吗?

在C中,您无法分配数组。 您必须明确复制内存。

可能你想这样做:

 memcpy(buf, measurements, sizeof(measurements)); 

但是你没有详细说明你真正想做什么。

PS:你的fscanf()错了。 它应该采用将保存读取值的变量的地址。

如果你使用uint32_t你应该使用SCNu32规范,以确保你不会破坏:

 fscanf(fp,"%"SCNu32, &InterruptLatency); 

您正在尝试将指针值分配给数组。 你不能这样做。

使用memcpy:

 memcpy(buf, &measurements, sizeof(measurements));