Closed PavelVozenilek closed 4 years ago
The current design is that every operation on a pointer operates on the pointed-to value. So they're more like C++ references in that way. I think this should be clarified in the documentation.
In fact, I wonder if the pointer type syntax should be changed to T&
to make this behavior more intuitive to people familiar with C++ references. And maybe start calling them "references" as well.
Currently to do pointer arithmetic, so called "array pointers", T[*]
, need to be used. They're called that way, and the syntax is like that, because pointer arithmetic only makes sense on arrays. For example:
void main() {
int i = 6;
int[*] p = &i;
p++;
println(p[-1]); // prints 6
}
Yes, this (reference) would be more intuitive.
Yes, references and T&
could be better for Delta given their established behavior in C++. I'll think about it.
I also improved the pointer documentation now.
I tried to modify example for pointers, to:
I expected it not to compile, to crash, or print some nonsense, but got 9. It feels nonintuitive, that invisible dereference.