Skip to content

Document pass-by-reference behavior for large arguments#287

Open
Feoramund wants to merge 1 commit intoodin-lang:masterfrom
Feoramund:doc-alias-bugs
Open

Document pass-by-reference behavior for large arguments#287
Feoramund wants to merge 1 commit intoodin-lang:masterfrom
Feoramund:doc-alias-bugs

Conversation

@Feoramund
Copy link
Copy Markdown
Contributor

This was discussed in odin-lang/Odin#2971 but I couldn't find any mention of it on the overview. I used @jakubtomsu's initial example with expanded names so the problem is more clear.

It would be good if we could get an exact and explicit definition of what is a "large" argument.

@jakubtomsu
Copy link
Copy Markdown
Contributor

Good idea.
Btw I'm not sure if the calling convention uses different thresholds on different compilation targets though. It might be a good idea to standardize it to always be size_of(rawptr) * 2, (which is what linux RISC-V calling convention does for example)

Comment thread content/docs/overview.md
fmt.println(sum(..odds)) // 9, passing a slice as varargs
```

**Note:** Odin makes a compromise for the sake of performance in that large arguments (as determined by the compiler) are internally passed by reference (as opposed to always copying them to the stack, as C does) and this can have surprising consequences if you are not aware of it. Here's an example:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is now defined as always >16 bytes now. <= 16 bytes will always be "pass by value".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants