4 ms·
C has inline, are you talking about older versions?
by pipeline_peak 3y ago
C has inline, are you talking about older versions?
- pjmlp 3y agoInline is an hit, doesn't mean it gets really expanded, that is why compilers have extensions for "I really mean it, inline no matter what". C++ templates provide the mechanism to really inline complex code, run it at compile time and just place the result into the binary, instead of clunky preprocessor macros.
- mike_hock 3y agoInlining 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."