3 ms·
That's been done before. The original Modula 1 compiler had that. In a language where the default parameter mode is a read-only reference, it's an obvious optim
by Animats 4y ago
That's been done before. The original Modula 1 compiler had that. In a language where the default parameter mode is a read-only reference, it's an obvious optimization.
The reverse is true. Anything passed by value can be treated as const reference by the compiler if the compiler knows enough about access and lifetime. The compiler must be able to determine that the parameter is neither deallocated nor modified while the function is using it. Rust compilers should be able to do that.
- mhh__ 4y agoD and I think Fortran can also do this
- dfawcus 4y agoThe MIPS NUBI ABI from 2005 also proposed this for C: ftp://ftp.linux-mips.org//pub/linux/mips/doc/NUBI/MD00438-2C-NUBIDESC-SPC-00.20.pdf Section 3.4, page 21: "Arguments: [...] Derived types (structures etc) and non-standard scalar types are passed in a register if and only if their memory- stored image is register-size aligned and fits into a register. [...] All other arguments are passed by reference. The callee must copy the argument if it writes it or takes its address."