Pass-by-value vs Pass-by-reference--James Mitchell
Complex world.
Pass-by-value vs Pass-by-reference
by James Mitchell
From the article:
Let’s dig into the age old question, should you pass-by-value or pass-by-reference in C++? (or by pointer in C)
This blog post is mostly a re-post of a reddit comment that I made on r/cpp about pass-by-value and pass-by-reference, with some minor improvements, to make it easier to reference and save.
The answer isn’t as easy as it might seem, it depends on the Application Binary Interface (ABI) and your use-cases, there isn’t a one size fits all answer, this is even more the case for anything which is built to be cross platform.
First it’s probably good to break the problem down into two parts (focusing solely on performance, ignoring readability and maintainability which should often be more important)
- The language construct costs (copying, moving, etc)
- Compiler implications (aliasing, pointer provenance, etc)
- The ABI (the stack, registers, etc)...

The third CppCon 2022 keynote has been announced! Daniela Engert is the world's top guru on C++ modules who isn't one of the compiler implementers, and will speaking about modules and so much more:
CppCon 2022 will kick off on Monday, September 11 with Bjarne Stroustrup delivering the traditional opening keynote live in person in Aurora. Bjarne’s annual opening keynote for CppCon is one of the most anticipated and most watch talks in C++, and among the most viewed presentations on the
Registration is now open for CppCon 2022, which starts on September 11 and will again be held