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

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -