IT lexicon › Programming › Struct return (sret)

Struct return (sret)

Programming På svenska → Updated: 2026-11-05

The ABI mechanism for returning values too big for registers: the caller passes a hidden pointer to the memory where the result should go.

In the x86-64 System V ABI, small structs come back in rax and rdx. Anything larger than 16 bytes is returned through memory: the caller reserves space, passes its address as an invisible first argument in rdi, and the callee writes there and hands the same address back in rax. Every visible argument shifts one register to the right as a result. In LLVM IR it shows up as the sret parameter attribute.

It is also what makes C++ copy elision cheap: the object is constructed straight into the caller's reserved slot and never needs copying. The trap is at language boundaries. A foreign declaration that gets the size or layout wrong shifts every single argument, and the bug surfaces as garbage values far from the cause.

← Back to the lexicon