问题
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