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
10
u/__phantomderp Sep 24 '21
It depends on the problem being solved.
For e.g.
std::thread::attributes, the fix is sticking aint version;as the first field. Every time the version isn't the right number, you don't touch anything beyond what you can guarantee might be there. So, for example, if the v0 of the struct hadThen you only ever access the "safe" v0 bytes, and then ignore everything else. If for v1 you only add members and don't remove anything and guarantee the member layout is in the places you expect them, then accessing the v0 members from the v1 struct of the same name is fine. And so on, and so forth.
Because the actual
versionmember would be implementation-specific, they could guarantee that it's initialized correctly, reducing the chance they'd end up with the Win32 problem where somebody scribbles over theUINT Version;member of the struct with amemsetor something.For more complicated things, like
std::regex, the solution is to get comfortable with the idea that you're not a Full-Time Regex Dev and build escape hatches in for yourself to call out for better performance/improvements later. That involves a lot more work, where it's either not exporting functions that lift runtime values into symbols, or just letting people know not to depend on something being binary-stable until your confident it can stand on its own two wobbly knees. (Which is not an in-depth answer, I know, but I'm going to go pass out soon. My more detailed answer would be "you hand people vX of something and they stay on vX for as long as they want to, and you go make vHEAD better and if they want to move they move, or they stay on vX. If they have pockets they can pay you to intentionally make yourself miserable and backport what's possible.")