문제

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
}
도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top