In order to use OSAtomicDecrement (mac-specific atomic operation), I need to provide a 4-byte aligned SInt32.
Does this kind of cooking work ? Is there another way to deal with alignment issues ?
struct SomeClass {
  SomeClass() {
    member_  = &storage_ + ((4 - (&storage_ % 4)) % 4);
    *member_ = 0;
  }
  SInt32 *member_;
  struct {
    SInt32 a;
    SInt32 b;
  } storage_;
};
If you're on a Mac, that means GCC. GCC can auto align variables for you:
  __attribute__((__aligned__(4))) int32_t member_;
Please note that this is not portable across compilers, as this is GCC specific.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With