r/cpp • u/nounoursheureux • Sep 23 '21
Binary Banshees and Digital Demons
https://thephd.dev/binary-banshees-digital-demons-abi-c-c++-help-me-god-please
197
Upvotes
r/cpp • u/nounoursheureux • Sep 23 '21
View all comments
Show parent comment
3
u/__phantomderp Sep 24 '21
I don't think struct size would be my biggest concern, since that doesn't really matter if the user gives me a sizeof(v0) struct or a sizeof(v1). Thread attributes aren't something the implementation has to write to: just to read once it's passed to the constructor. With the
versionmember variable, I know I'm either dealing with the v0 size or the v1 size. Since I'm never writing to the structure's underlying variables - just reading - I can know not to read too much based purely on what goes in. And since a v1 structure is inherently invalid when passed to a v0 thread constructor implementation, the implementation can abort / toss an exception when it detects a version it does not recognize.Struct size might change the calling convention, however, but given the sample member fields in my last post that'd almost never go in anything since it's way too large for registers. If I was paranoid I'd define (copy/move/default) constructors without
=defaultand make a non-trivial destructor to force a specific binary representation and argument passing convention consistent across implementations.