First Draft: ref For Variable Declarations
Walter Bright
newshound2 at digitalmars.com
Fri May 3 03:15:28 UTC 2024
Sure, they're all different.
> in C#, to pass by reference, you have to put ref also before the argument in
the function call
That makes refactoring much more work. By putting ref at the function
declaration, you can switch it on and off without having to change anything else.
C++ can have refs to null:
```
int *p = NULL;
int& r = *p;
```
You're not supposed to do that, but compilers don't detect it.
As for Zig, in D a ref is a single element pointer, a [] is a pointer to an array.
A special pointer to a 0 terminated array does not confer any useful semantics I
can think of - one could do it in D by just making the pointer a field in a
struct and overload the operators.
Essentially, we're in good shape here.
More information about the dip.development
mailing list