Warning different width?

  • I made a category on NSNumber for working with unichar's:

    .... NSHMNumberAdditions.h ....
    #import <Foundation/Foundation.h>
    /*!
    @method numberWithUnichar:
    @abstract ....
    */
    + (NSNumber *) numberWithUnichar: (unichar) character;

    .... NSHMNumberAdditions.c ....
    #import "NSHMNumberAdditions.h"
    @implementation NSNumber (NSHMNumberAdditions)
    + (NSNumber *) numberWithUnichar: (unichar) character; {
    return [NSNumber numberWithUnsignedShort: character];
    }
    ....

    But then XCode gives me the following WARNING on the line with the
    return:

    warning: passing argument 1 of 'numberWithUnsignedShort:' with
    different width due to prototype

    In the documentation I read for NSNumber:

    Creates and returns an NSNumber object containing a given value,
    treating it as an unsigned short.
    + (NSNumber *)numberWithUnsignedShort:(unsigned short)value

    while in NSString.h (included through Foundation.h) the unichar is
    defined by:

    typedef unsigned short unichar;

    It escapes me what is wrong here. Do I miss something or is perhaps
    the compiler overcautious here?

    Hans van der Meer
  • On Dec 24, 2007 6:19 AM, Hans van der Meer <hansm...> wrote:
    [snip]
    > But then XCode gives me the following WARNING on the line with the
    > return:
    >
    > warning: passing argument 1 of 'numberWithUnsignedShort:' with
    > different width due to prototype
    >
    > In the documentation I read for NSNumber:
    >
    > Creates and returns an NSNumber object containing a given value,
    > treating it as an unsigned short.
    > + (NSNumber *)numberWithUnsignedShort:(unsigned short)value
    >
    > while in NSString.h (included through Foundation.h) the unichar is
    > defined by:
    >
    > typedef unsigned short unichar;
    >
    > It escapes me what is wrong here. Do I miss something or is perhaps
    > the compiler overcautious here?

    You're using the "-Wconversion" flag. That warning flag doesn't do
    what you think it does :)
    For modern C code (i.e. code written after C was standardized in
    1989), it is essentially useless.

    --
    Clark S. Cox III
    <clarkcox3...>
previous month december 2007 next month
MTWTFSS
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31            
Go to today