incompatible type C error?

℡╲_俬逩灬. 提交于 2019-12-12 04:50:03

问题


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
}

ERROR : incompatible type when assigning of type char[256] from type uint8 (*)[32]

could some one help me how to solve this ??


回答1:


In C you cannot assign arrays. You have to copy the memory explicitly.

Probably you want to do this:

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

But you gave no details about what you actually want to do.

PS: Your fscanf() is wrong. It should take the address of the variable that will hold the read value.

And if you use uint32_t you should use the SCNu32 specification, from <inttypes.h>, to be sure that you do not break things:

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



回答2:


You are trying to assign a pointer value to an array. You can't do that.

Use memcpy:

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


来源:https://stackoverflow.com/questions/23336289/incompatible-type-c-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!