Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:35:22+00:00 2026-06-17T11:35:22+00:00

I’m having an odd problem with obj c adding an extra byte to by

  • 0

I’m having an odd problem with obj c adding an extra byte to by uint8_t array.

Here are the two methods that are involved:

ViewController.m

- (void)viewDidLoad {
    // hexData = NSData object
    const uint8_t *hexBytes = [hexData bytes];

    // header is first 3 bytes
    uint8_t headerBytes[] = {hexBytes[0],hexBytes[1],hexBytes[2]};

    // output the size
    NSLog(@"View did load header size: %lu", sizeof(headerBytes));

    // create a MessageHeader object
    MessageHeader *messageHeader = [[MessageHeader alloc] initWithBytes:headerBytes];
}

MessageHeader.h

- (id)initWithBytes:(uint8_t *)bytes {
    self = [super init];
    if(self != nil){
        NSLog(@"Message header init bytes size: %lu", sizeof(bytes));
        NSData *data = [NSData dataWithBytes:bytes length:sizeof(bytes)];
        self.bytes = bytes;
    }
    return self;
}

Console output

View did load header size: 3

Message header init bytes size: 4

This is very strange! Outputting the bytes to the screen shows that an extra byte has been appended to the data for no apparent reason. If eef231 is the input then eef23150 is the output in the init method. That extra byte is seemingly random.

I wonder if it could be the cast between uint8_t headerBytes[] and uint8_t *bytes in the init method.

If anyone has any more info on it that would be great. Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:35:23+00:00Added an answer on June 17, 2026 at 11:35 am

    sizeof is a compile time operator and doesn’t do what you think it does.

    sizeof on an uint8_t[] gives you the size of that array, which is 1 byte * 3 elements = 3 bytes. It can do this because the array declaration has implicit size information attached.

    sizeof on an uint8_t* gives you the size of a pointer, which is 4 bytes on 32 bit systems.

    See the wikipedia article on sizeof for a good idea of what it does.

    If you want to pass the length of the array, the general convention is to pass an additional length paremeter. Since you are working in objective c, you should pass around an NSData, which can contain an array of data, and also its size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I've tracked down a weird MySQL problem to the two different ways I was
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I am confused How to use looping for Json response Array in another Array.
I've got a string that has curly quotes in it. I'd like to replace
I have a small JavaScript validation script that validates inputs based on Regex. I
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a
We're building an app, our first using Rails 3, and we're having to build

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.