c++ - How to ensure a member is 4-byte aligned? -


To use the OSAtomicDecrement (MAC-specific nuclear operation), I need to provide a 4-byte alliance SInt32 .

Is there such a cooking job? Another way to deal with alignment issues?

  struct SomeClass {SomeClass () {member_ = & amp; Collection_ + ((4 - (and storage_% 4))% 4); * Member_ = 0; } SInt32 * member_; Struct {SInt32 a; SInt32b; } Storage_; };  

If you are on a Mac, this means GCC. GCC can auto-align for you:

  __ distributed (__ aligned __ (4)) int32_t member_;  

Please note that this is not portable for compilers because it's GCC specific.


Comments

Popular posts from this blog

asp.net - Change the driver in the connection string to a data source in VB.Net -

Getting started consuming web services in a Ruby on Rails 3 application -

objective c - iPhone and it's wireless area -