• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: sizeof(aStruct) in Xcode 4
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sizeof(aStruct) in Xcode 4


  • Subject: Re: sizeof(aStruct) in Xcode 4
  • From: Tony Romano <email@hidden>
  • Date: Tue, 21 Jun 2011 13:04:46 -0700
  • Thread-topic: sizeof(aStruct) in Xcode 4

Sizeof is telling you the number of bytes the structure is consuming and as you have discovered, it can be different than the summation of the data types.  This is because of memory alignment for a given architecture.

What is the error?

Tony Romano

From: "McLaughlin, Michael P." <email@hidden>
Date: Tue, 21 Jun 2011 15:39:30 -0400
To: "email@hidden" <email@hidden>
Subject: sizeof(aStruct) in Xcode 4

I am porting a legacy project from Xcode 3.2.6 to Xcode 4.0.2.  I am using LLVM 1.7 in the former and LLVM 2.0 in the latter.  Also using LLDB.  My computer is a 64-bit Mac Pro but the target is set to 32-bit Intel and Snow Leopard for legacy reasons.

The problem is with two structs:

struct AA {
   int n;
   double val;
};

struct BB {
   short ss, tt;
   double val;
};

sizeof(AA) and sizeof(BB) both come out as 16 even though they "should" be 12.  I pack sequences of these structs into NSData objects (at which point they are 12 bytes) and pass them (NSPipe) to some subprocesses (NSTask) running independently.  As such, sizeof(struct …) is important in the conversion of NSData to something else.

Clearly, I am confused by the proliferation of int types and unsure what the recommended practice should be to avoid these errors.

Any tips?

Thanks in advance.

--
Michael P. McLaughlin
_______________________________________________ Do not post admin requests to the list. They will be ignored. Xcode-users mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

References: 
 >sizeof(aStruct) in Xcode 4 (From: "McLaughlin, Michael P." <email@hidden>)

  • Prev by Date: Re: sizeof(aStruct) in Xcode 4
  • Next by Date: Re: sizeof(aStruct) in Xcode 4
  • Previous by thread: Re: sizeof(aStruct) in Xcode 4
  • Next by thread: Re: sizeof(aStruct) in Xcode 4
  • Index(es):
    • Date
    • Thread