4 ms·
Why is it undefined behavior?
by michalhosna 5y ago
Why is it undefined behavior?
- steerablesafe 5y agoIt looks like it's a C++ standard library requirement: https://eel.is/c++draft/macro.names#2 https://eel.is/c++draft/macro.names#2 Otherwise this is one of the unintended effects (on Itanium ABI): https://godbolt.org/z/bY4534zhc https://godbolt.org/z/bY4534zhc
- alternatetwo 5y agoFYI, MSVC doesn't do this. I use this same hack in a project where I need access to private/protected members in the current stage, and memory layouts need to match ... You gave me a bit of a heart attack there. mingw gcc (11.2.0) does have the same 8 vs 12 difference.
- steerablesafe 5y agoMSVC might not alter layout, but public and private member functions have different name mangling: https://godbolt.org/z/ddqd3vr5x https://godbolt.org/z/ddqd3vr5x Notice the call to `?foo@A@@AEAAXXZ` in one compilation and `?foo@A@@QEAAXXZ` in the other, supposedly to the same function. You might get fun linker errors this way, possibly nothing nastier though.
- alternatetwo 5y agoYeah, I'm aware of that. I've had to edit mangled names a few times too many - transferring between idbs and changing const char * to char * (PBD to PAD I think? thankfully I'm already not sure anymore), for example. Or changing __int64 to int ... Luckily I don't need to link anything, so I don't care about that for now.