Posts

Showing posts with the label Assembler

C++ : Pass-By-Reference Or Die

Image
Before today's Post, I'm on a mission folks, to get 1000 subs on YouTube.  If only 5% of viewers here subscribed we've have met this target in one month... I've just had group code review of one of my personal projects, and been rather surprised by the vitriol levelled at one of my practices.... Pass by Reference. The reviewer, one of a group of peers, has had major issues with the project (my personal) insistance on passing by reference wherever possible, in C++ this takes the form of an additional ampersand on parameter definitions; maybe this was the chaps problem, he has to type an ampersand? So his problem?  Well, without the actual code we'll simplify and use the Compiler Explorer (from Godbolt.org) and we'll take up their basic square function example, it starts up thus: Giving the assembler: On the right, and this chap had taken time to prepare a whole slide show of functions, usually simple, and present them at this code review, showing this kind of t...

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...