Hi,
"kingdomzhf" <an*******@discussions.microsoft.com> wrote in message
news:48**********************************@microsof t.com...
Following macro is found inside Microsoft C++ source code:
#define _INTSIZEOF(n) ( (sizeof(n) + sizeof(int) - 1) & ~(sizeof(int) -
1) ) The result between _INTSIZEOF(n) and sizeof(n) are always the same. I'm
not sure why they defined this one. Specifically, what's the purpose of
minus one for ?
The macro aligns arbitrary memory block sizes to their 4-byte-block
equivalents. That means every block size that is not a multiple of four is
rounded up towards the next multiple of four. This is done by incrementing
the current block size by 3 (first part of the macro) and cutting off the
last 2 bits which equals a modulo-4 operation (second part of the macro).
Hence, the macro's output for a char[3], char[6], char[11] should be 4, 8,
12, rather than sizeof(s) output of 3, 6, and 11.
This macro probably helps allocating memory blocks that must have an aligned
block size, e.g. bitmaps.
regards,
Andreas