Closed
Description
EDIT
- Latest iteration of the proposal: Pointer Reform #770 (comment)
- Progress: Pointer Reform #770 (comment)
&
only used for address-of, no longer designates a pointer type. Necessary because of #588
^
pointer to exactly 1 thing.[*]
pointer to a block of memory of unknown length[*]null
pointer to block of memory, null-terminated (or 0 terminated for integers). proposal: type for null terminated pointer #265[]
pointer to a block of memory with runtime known length. status quo slices.[]null
pointer to a block of memory with runtime known length, with a null/0 at ptr[len][N]
pointer to a block of memory with comptime known length[N]null
pointer to a block of memory with comptime known length, and a null/0 at ptr[N]
All of them support pointer indexing and slicing except ^
. Only [*]
supports pointer arithmetic. All of them implicitly cast to [*]
. []null
and [N]null
implicitly cast to [*]null
.
&ptr[x]
and&foo
always gives a^
.ptr[x..y]
with comptime known x and y gives a[N]
.array[x..]
gives a[N]
.
new array syntax
var array: 4*i32 = undefined;
Now it is clear whether you should do &array
or &array[0]
. Don't use &array
. If you want a [N]T
, e.g. a pointer with comptime known length, use array[0..]
. If the function wants to access more than one element, you'll do this. Otherwise, &array[0]
, will give ^T
, which would trigger a compile error if the array was length 0, and only this element can be accessed via this pointer.