Posts

Showing posts with the label embedded

C/C++ Stop Miss using inline.... PLEASE!

Image
This is a plea, from the bottom of my rotten black heart, please... Please... PLEASE stop miss using the inline directive in your C and C++. Now, I can't blame you for this, I remember back in the 90's being actually taught (at degree level) "use inline to make a function faster", and this old lie still bites today. inline does not make your function faster, it simply forces the compiler to insert "inline" another copy of the same code whenever you call it, so this code: #include <iostream> inline void Hello() {     std::cout << "Hello"; } int main () {     Hello();     Hello();     Hello(); } Turns into the effective output code of: int main () {     std::cout << "Hello";     std::cout << "Hello";     std::cout << "Hello"; } What does this mean in practice?  Well, you saves yourself a JMP into the function, and the position on the stack holding the return address, and the RET from t...