compiler warning when attempting to save hex value in char in reusing it

  • I've been working with XCode and Cocoa for a few days now and got a little
    stuck with a problem:
    char seq =  0x02;
    NSMutableData *sequence = [[NSMutableData alloc] init];
    [sequence appendBytes:seq length: 1];

    I always get a warning from the compiler telling me:  warning: passing
    argument 1 of 'appendBytes:length:' makes pointer from integer without a
    cast
    *
    *
    When I start the application I can work with it, but I think there might be
    a general mistake I make with chars and hex values. I looked all over the
    internet and was not able to find why that is so far. Could you explain me
    how I can put a hex character into a char and then hand that over to a
    NSMutableArray without a warning and those cast problems.

    Thanks
    Sebastian.
  • You want to pass a pointer to the seq, not the seq itself.

    so,

    [sequence appendBytes:&seq length:1];

    On Sep 4, 2007, at 5:03 PM, Sebastian Pape wrote:

    > I've been working with XCode and Cocoa for a few days now and got a
    > little
    > stuck with a problem:
    > char seq =  0x02;
    > NSMutableData *sequence = [[NSMutableData alloc] init];
    > [sequence appendBytes:seq length: 1];
    >
    >
    > I always get a warning from the compiler telling me:  warning: passing
    > argument 1 of 'appendBytes:length:' makes pointer from integer
    > without a
    > cast
    > *
    > *
    > When I start the application I can work with it, but I think there
    > might be
    > a general mistake I make with chars and hex values. I looked all
    > over the
    > internet and was not able to find why that is so far. Could you
    > explain me
    > how I can put a hex character into a char and then hand that over to a
    > NSMutableArray without a warning and those cast problems.
    >
    >
    > Thanks
    > Sebastian.
  • --- Sebastian Pape <sebastianderpape...> wrote:

    > I've been working with XCode and Cocoa for a few
    > days now and got a little
    > stuck with a problem:
    > char seq =  0x02;
    > NSMutableData *sequence = [[NSMutableData alloc]
    > init];
    > [sequence appendBytes:seq length: 1];
    >
    >
    > I always get a warning from the compiler telling me:
    > warning: passing
    > argument 1 of 'appendBytes:length:' makes pointer
    > from integer without a
    > cast

    It's telling you precisely what's wrong: The method
    expects a pointer, but you're giving it a character
    value. If you want to append the contents of seq to
    the data, it should be [sequence appendBytes:&seq
    length:1].

    Cheers,
    Chuck


    ____________________________________________________________________________________
    Need a vacation? Get great deals
    to amazing places on Yahoo! Travel.
    http://travel.yahoo.com/
previous month september 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
Go to today