Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

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

  • 17-12-2008 06: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, Registered Users 2 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