to pass and return, the story of functions, values and compilers
summary
Compilers and experiments decide: code and measurements show that everything becomes a value at the machine level — registers or pointers, tests use gcc clang icc and MSVC on x86_64 via Compiler Explorer with max optimization and C++20, and two compilers (gcc and clang) routinely elide copies while icc and especially MSVC sometimes produces one or two full copies or temporaries for 16–40 byte and larger objects. C++17 mandates prvalue elision, but real builds reveal surprising deviations and concrete register/stack calling details.
AI-written summary · about
chapters (13)
- 0:00Introduction
- 1:45Ways to pass and return
- 2:29Everything is passed by value
- 11:35Returning by value
- 16:40MSVC
- 20:35Mental model
- 25:42Michael Timon
- 26:28Full copy allegiance
- 30:02String
- 34:40Assignment
- 46:12Passing by value
- 54:14Passing by reference
- 55:47Questions
related talks
01h 03mHidden Overhead of a Function API
01h 03mUnlocking the value of C++20
01h 02mBack to Basics: The Structure of a Program
01h 50mUnderstanding Compiler Optimization
11mThe New Old Thing, of Fun with Lambdas
08mOn "simple" Optimizations
01h 06mBack to Basics: Functions in C++
54mCompile-Time Validation in C++ Programming
