Question

warning : passing argument 2 of ‘memcpy’ makes pointer from integer without a cast [enabled by default]

uint8 InterruptLatency;
char buf[256];
int kernelinterrupt time()
{
    fscanf(fp, "%"SCNu8"\n", &InterruptLatency);  // I am reading the data from kernel which is not shown here
  memcpy(buf, InterruptLatency, sizeof(InterruptLatency));   // warning here as above

    // after storing it in buffer I am sending the data from but to another layer
}
Was it helpful?

Solution

The memcpy() function expects two pointers, but InterruptLatency is an 8-bit integer.

The solution is to take the address of the variable:

memcpy(buf, &InterruptLatency, sizeof InterruptLatency);
            ^
            |
        address-of
        operator

Note that no parentheses are needed for sizeof when taking the size of an actual object. This is because sizeof is not a function.

Also note that using memcpy() for copying a single byte into a byte array like this would never happen in "real" C code. I'd just do:

buf[0] = InterruptLatency;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top