3 ms·
> This is one advantage of Ada, where parameters are abstractly declared as "in" or "in out" or "out". Also Fortran has "in", "inout" and "out".
by sampo 4y ago
> This is one advantage of Ada, where parameters are abstractly declared as "in" or "in out" or "out".
Also Fortran has "in", "inout" and "out".
- pletnes 4y agoFortran also has «default» / no intent. This is somehow different from inout.
- trifurcate 4y agoAlso, MSVC has similar annotations for various static analyses: https://learn.microsoft.com/en-us/cpp/code-quality/understanding-sal?view=msvc-170 https://learn.microsoft.com/en-us/cpp/code-quality/understan...
- jb1991 4y agoAnd Swift also has "inout" parameters.
- stephencanon 4y agoBut not “out” params, sadly. It can return multiple values, so this doesn’t matter much for value types, but it would be nice to be able to specify that a pointer arg is an out-param sometimes and enforce that it is not read from while handling allocation in the caller.
- wiz21c 4y agoand GL/SL IIRC ...
- FpUser 4y agoSo does Delphi / FreePascal
- Congeec 4y agoC++23 is not too late to the party https://en.cppreference.com/w/cpp/memory/out_ptr_t/out_ptr https://en.cppreference.com/w/cpp/memory/out_ptr_t/out_ptr
- int_19h 4y agoSo far as I can tell, it's not quite the same thing since these still have pointer semantics (and thus have to deal with aliasing etc). The in/out approach is more generic, since "in" can map to a pointer where it makes sense, and to a copy where it does not. Better yet when you prohibit such arguments from aliasing (or at least make no-alias the default) - now the compiler can also implement "in out" by copying the value back and forth, if it's faster than indirection.
- IAmLiterallyAB 4y agoEhh that's not quite what those are. The types being added for C++23 are designed for FFI. Herb made a proposal for proper in/out parameters for C++ in 2020 https://youtu.be/6lurOCdaj0Y https://youtu.be/6lurOCdaj0Y