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 7002027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:52:37+00:00 2026-05-27T20:52:37+00:00

I am converting some Objective-C++ code into plain Objective-C and I am having some

  • 0

I am converting some Objective-C++ code into plain Objective-C and I am having some trouble with structs. For both languages, I have the struct declared in the .h file like this.

struct BasicNIDSHeader {
    short messageCode;
    short messageDate;
    int messageTime;
    int messageLength;
    short sourceID;
    short destID;
    short numberOfBlocks;
};

In C++, the struct is being declared like

BasicNIDSHeader header;

and in Objective-C I do this

struct BasicNIDSHeader header;

The code for using them is actually the same in both languages.

memset(&header, 0, sizeof(header));
[[fileHandle readDataOfLength:sizeof(header)] getBytes:&header];

where fileHandle is a NSFileHandle.

The problem is than in the original C++ code, sizeof(header) = 18. When using Objective-C, sizeof(header) = 20.

Any ideas why this is happening or how to fix it? The code is dependent on the size being like it is in C++. I can just hardcode it, but would like to have a better understanding of why it is happening. Plus I hate hardcoding constants.

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-05-27T20:52:38+00:00Added an answer on May 27, 2026 at 8:52 pm

    If you depend on the internal memory structure of your structs – you should disable padding. This is called “packed”, and different compilers have different ways of signalling it.

    In GCC you do this with the __attribute__ keyword. Details here.

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

Sidebar

Related Questions

I am having trouble converting some code from VB6 to VB.NET (I don't have
I've got some C# code that I'm converting to Objective-C. In C# I would
I am having some trouble converting an old project from VS6 to VS2005. At
Possible Duplicate: Byte array in objective-c Am converting some Java code to Objective-C and
I'm converting some C# code into VB.Net and was stuck on second half of
I am converting some Objective C code to C# for use in a Monotouch
I am converting some Java code to C# and have found a few labelled
I'm having difficulty converting some NSOperation code to ARC. My operation object uses a
I am converting some Java code to C#. This code is using getGlyphOutline from
I'm in the process of converting some LaTeX documentation to restructured text and having

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.