4 ms·
Inlining a struct of callbacks is a much more brittle optimization in C than inlining calls to member functions on a class accepted as a template argument in C+
by mike_hock 3y ago
Inlining a struct of callbacks is a much more brittle optimization in C than inlining calls to member functions on a class accepted as a template argument in
C++, which I consider a fair comparison because the former is the closest approximation C has for the latter.
You might get a failure to inline and get direct calls to fixed function addresses in the latter case, but never virtual calls (unless the member functions themselves are virtual, of course). The former case relies on the compiler seeing through the entire call chain and being able to prove that the function pointers don't change.
The idea that virtual calls can bite you in C++ but not in C is clearly nonsense, as in any situation where you'd need a virtual function in C++, you'd need a function pointer in C, and virtual functions don't happen accidentally as you have to explicitly write "virtual."