Re:Overriding C++ virtual functions at run time
by leni536 on Sunday August 09, 2020 @07:01AM
(#24098756)
In other words if your program relies on undefined behavior then make sure you look at your compiler's documentation and then you might be able to make it implementation defined.
[ Parent
| on HN ]
Re:Overriding C++ virtual functions at run time
by formerly_proven on Sunday August 09, 2020 @09:20AM
(#24099438)
The C++ standard is written in such a way that a vtable as the first member of a polymorphic class instance is the obvious way to satisfy the standard's demands. I don't think there is any mainstream C++ implementation that doesn't use vtables, although some older C++ compilers used a slightly different layout.
The fact that inside a single CU an optimizing compiler can determine the targets of polymorphic dispatch statically is unrelated, because most usage scenarios (more than one CU, external modules) preclude such optimizations anyway.
vtables aren't undefined, they are implementation defined and part of the C++ ABI. As soon as you expose something through the C++ ABI the compiler has to use the ABI's definitions.
Re:Overriding C++ virtual functions at run time
by qppo on Sunday August 09, 2020 @01:42PM
(#24101311)
People might bring up that the only ABI that is "stable" is Itanium, while MSVC has historically broken ABI stability quite regularly until fairly recently (2017, iirc?).
That said, so much software on Windows relies on vtable layout that breaking their particular implementation in the ABI would be a massive breaking change, so it's unlikely that it will happen.
Re:Overriding C++ virtual functions at run time
by gpderetta on Sunday August 09, 2020 @05:06PM
(#24102903)
I'm not a Windows programmer,but IIRC vtable layout is very thightly tied to COM so I doubt that MS has broken or will break this specific bit of the ABI anytime soon.