不兼容的C型错误?

不兼容的C型错误?,c,arrays,pointers,memory,interrupt,C,Arrays,Pointers,Memory,Interrupt,错误:从类型uint8(*)[32]分配类型char[256]时,类型不兼容 有人能帮我解决这个问题吗???在C语言中,你不能分配数组。您必须显式复制内存 可能您想这样做: uint32 InterruptLatency; uint8 measurements[32]; char buf[256]; int kernelinterrupt time() { fscanf(fp,"%lu", InterruptLatency); // I am reading the data from ker

错误:从类型uint8(*)[32]分配类型char[256]时,类型不兼容


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

在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
}
但你没有透露你真正想做什么的细节

注:您的
fscanf()
是错误的。它应该采用保存读取值的变量的地址

如果使用
uint32\t
,则应使用
中的
SCNu32
规范,以确保不会损坏:

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

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

使用memcpy:

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

你能用空格写函数名吗?按buf=&measurements;您打算做什么?错误消息包含所有信息。在提供答案后,请不要更改您的问题,因为这可能会使某些答案无法理解。将对您的问题的修改添加为更新。参考我上面的评论,我回滚了对您的问题的最后一次修改。
“l”
长度修饰符也意味着在OP的平台上,
long
s应为32位。是这样吗?@alk:OP是什么意思?很多人都在写OP。我在谷歌上搜索过,但我没有得到确切的答案?@alk:你说得对,正确的方法是使用
中的宏。已更正。@user3458454:如果变量是
uint32\u t
,则不能保存64位值。使用
uint64\u t
SCNu64
进行测试。我问了一个新问题:
memcpy(buf, &measurements, sizeof(measurements));