Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

warning: pointer targets in passing argument 1 of strncpy differ in signedness

Options
  • 17-12-2008 6:17pm
    #1
    Closed Accounts Posts: 2,110 ✭✭✭


    warning: pointer targets in passing argument 1 of ?strncpy? differ in signedness

    Does anybody know what this means?

    I'm passing in an int8_t pointer to the strncpy function

    void myfunc(int8_t * x)
    {
    ...

    strncpy(x,y,z);
    }

    If i cast x from being int_t * to be void * or char * the warning goes away. I don't understand the signedness warning though?

    How does a char * differ in signedness from a int8_t *?


Comments

  • Registered Users Posts: 885 ✭✭✭clearz


    The C and C++ standard defines three distinct types of char.
    signed char
    unsigned char
    char
    
    The reason for this dates back to the original 1978 C where there was no signed type for char or int. This left it upto the individual implementations to decide whether char would be signed or unsigned. When the ANSI C standard was drafted and signed char was added to the spec they left char as a third type to have ambiguous signedness in order to keep backwards compatibility.
    As far as I know int8_t is typedef signed char while the first argument in strncpy is char* so depending on the compiler/platform this could be unsigned and you could run into some problems.


  • Closed Accounts Posts: 2,110 ✭✭✭Y2J_MUFC


    clearz wrote: »
    The C and C++ standard defines three distinct types of char.
    signed char
    unsigned char
    char
    
    The reason for this dates back to the original 1978 C where there was no signed type for char or int. This left it upto the individual implementations to decide whether char would be signed or unsigned. When the ANSI C standard was drafted and signed char was added to the spec they left char as a third type to have ambiguous signedness in order to keep backwards compatibility.
    As far as I know int8_t is typedef signed char while the first argument in strncpy is char* so depending on the compiler/platform this could be unsigned and you could run into some problems.

    Cheers, great explanation which it seems is dead on, as I'm running this in two different places, one gives the warning and one doesn't. This explains a lot! Thanks!


Advertisement