News for hackers. Stuff that matters.
Re:C and returning values quickly or safely, but not both by evmar on Friday January 19, 2024 @01:34AM (#39052225)
This article seems to make performance assertions that are not supported by what actually happens.

E.g. "Passing by value is slower, since a new variable has to be created. Passing by reference just passes an address and the code uses that address – no new variable is created." is not right for the example involving an int*, as passing a pointer is clearly as much data to copy as an int (and in the non-pointer case it will all end up in (faster) registers).

Similarly if you paste the "Returning a copy of a structure" example into godbolt you'll see GetDateTime4 writes directly into the caller's pointer. https://godbolt.org/z/Wj4Gn1YaP

There are no comments on this comment yet.