c++ – InterlockedIncrement usage

c++ – InterlockedIncrement usage

It depends on your compiler settings. However, by default, anything eight bytes and under will be aligned on a natural boundary. Thus an int we be aligned on a 32-bit boundary.

Also, the #pragma pack directive can be used to change alignment inside a compile unit.

I would like to add that the answer assumes Microsoft C/C++ compiler. Packing rules might differ from compiler to compiler. But in general, I would assume that most C/C++ compilers for Windows use the same packing defaults just to make working with Microsoft SDK headers a bit easier.

The code looks fine (variables will be properly aligned unless you specifically do something to break that – usually involving casting or packed structures).

c++ – InterlockedIncrement usage

Yes, this will work fine. Compilers usually do align unless instructed otherwise.

Leave a Reply

Your email address will not be published.