Thread: Compiler warning....what does it mean and how do I cast to fix it

  1. #1
    Registered User
    Join Date
    Mar 2020
    Posts
    37

    Compiler warning....what does it mean and how do I cast to fix it

    The following line of code generates a warning:
    code:
    Code:
                    memcpy(noCRC, pRx, 4);
    warning:
    argument of type "volatile char *" is incompatible with parameter of type "const void *__restrict__"

    Code:
    volatile char *pRx;
    char noCRC[4];
    I understand the types are different. I would like to know how do I cast to make the warning go away? Secondly I do not understand the void * for memcpy, is it expecting a pointer to a function here?

    Thanks

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,169
    > Secondly I do not understand the void * for memcpy, is it expecting a pointer to a function here?
    Then how do you know how to call the function.
    Not knowing what void* is is a pretty basic part of C knowledge.

    > "const void *__restrict__"
    This tells memcpy that
    - the memory isn't being pointed to by another pointer (like overlapping with the destination for example) - that's the __restrict__ part.
    - the memory could be any type - that's the void* part.
    - the memory won't be changed by memcpy - that's the const part
    - the memory won't spontaneously change - that's implied by the lack of volatile.

    pRx fails on this last point.

    > I would like to know how do I cast to make the warning go away?
    You could use a for loop.
    Code:
    for ( i = 0 ; i < 3 ; i++ ) noCRC[i] = pRx[i];
    Or show/explain why your pRx absolutely must be volatile.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. [warning] strcpy makes pointer from integer without a cast
    By HandsThatHold in forum C Programming
    Replies: 5
    Last Post: 08-14-2012, 08:16 AM
  2. pointer from integer without a cast - warning
    By Andreea Coman in forum C Programming
    Replies: 17
    Last Post: 01-11-2012, 02:48 PM
  3. int from pointer without a cast warning.
    By mrkrinkle in forum C Programming
    Replies: 4
    Last Post: 02-12-2010, 12:20 PM
  4. warning: cast to pointer from integer of different size
    By DavidDobson in forum C Programming
    Replies: 6
    Last Post: 12-03-2008, 06:37 PM
  5. Pointer from a cast warning
    By swgh in forum C Programming
    Replies: 4
    Last Post: 07-30-2007, 08:38 AM

Tags for this Thread