Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22195

g++ - size of a binary semaphore

$
0
0

I am using a binary semaphore in a struct like so:

struct Header {uint64_t otherfields...binary_semaphore sem;[hidden padding of 4 bytes if sem is 4 bytes]uint64_t post_otherfields..};int main() {cout << sizeof(Header) << endl;return 0;}

I tried on godbolt https://godbolt.org/z/8rPs56Y7x to see if different x86_64 compilers gave the same results of size 4 for the semaphore.

I set up u64 values in the struct on purpose to correct any hiccup.

Since this struct is in a mmap region:

I would like to get the guarantee that the size won't suddenly change in the future, using Linux GCC on x86_64 arch.

(more than 8 bytes will be problematic, taking into account the alignment occuring between sem and post_otherfields and that would mess up the layout)

Thanks


Viewing all articles
Browse latest Browse all 22195

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>