--- a/doc/langref.html.in +++ b/doc/langref.html.in @@ -3192,7 +3192,16 @@ fn foo() void { } {#code_end#} {#header_open|Pass-by-value Parameters#}

- In Zig, structs, unions, and enums with payloads can be passed directly to a function: + Primitive types such as {#link|Integers#} and {#link|Floats#} passed as parameters + are copied, and then the copy is available in the function body. This is called "passing by value". + (Note that copying a primitive type is essentially free and typically involves nothing more than + setting a register.) +

+

+ Structs, unions, and arrays can sometimes be more efficiently passed as a reference, since a copy + could be arbitrarily expensive depending on the size. When these types are passed + as parameters, Zig may choose to copy and pass by value, or pass by reference, whichever way + Zig decides will be faster. This is made possible, in part, by the fact that parameters are immutable.

{#code_begin|test#} const Point = struct { @@ -3211,10 +3220,6 @@ test "pass aggregate type by non-copy value to function" { } {#code_end#}

- In this case, the value may be passed by reference, or by value, whichever way - Zig decides will be faster. -

-

For extern functions, Zig follows the C ABI for passing structs and unions by value.

{#header_close#}