To use OSAtomicDecrement (atom-specific atomic operation), I need to provide a 4-byte aligned SInt32.
Does this type of cooking work? Is there any other way to solve alignment problems?
struct SomeClass { SomeClass() { member_ = &storage_ + ((4 - (&storage_ % 4)) % 4); *member_ = 0; } SInt32 *member_; struct { SInt32 a; SInt32 b; } storage_; };
If you are on a Mac, it means GCC. GCC can automatically align variables for you:
__attribute__((__aligned__(4))) int32_t member_;
Please note that this is not portable for compilers, as it is specific to GCC.
I would suggest that any SInt32 is already aligned, even on a Mac.
To clarify:
struct Foo { SInt32 member; };
member , char.
int 4 OS X. , , - (, , packed ..).
int
packed
Mac, , , 4- () . IIRC, . .
TR1 ( ++ 0x), std::aligned_storage.
std::aligned_storage
S A, std::aligned_storage<S, A>::storage.
S
A
std::aligned_storage<S, A>::storage
( . , TR1 , . MSVC std::tr1)
std::tr1
, 32- 4- ( , , 32- ints 4 )
, .
struct { Foo _hisFoo; unsigned int dummyAlignment : 0; Foo _myFoo; }
Source: https://habr.com/ru/post/1729717/More articles:jQuery 1.4 Dynamically created image format incorrect in IE8 and max-width - jqueryIs there a CASPOL.exe GUI command line generator? - .nethttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1729714/what-are-the-steps-to-create-ajax-login-in-yiiframework&usg=ALkJrhii0dRShbrB0N3RQmUBVpN2ZOrJdwVisual Studio 2008 (C #) with SQL Compact Edition database error: 26 - c #https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1729716/once-i-have-a-database-project-in-visual-studio-if-i-edit-a-stored-procedure-or-view-how-do-i-apply-the-changes-to-the-server&usg=ALkJrhhtrpr4GgTS4dznUl8_EvhHFkPB6Aregex for years interval - c #Is it enough to print a list of float lists? - pythonRight-click in Webkit view mode. - windowsJQuery hover event fired twice on mouse - jqueryEncrypt text for printing, so the result is still available for printing (can be printed) - encodingAll Articles