-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Pointer Reform #770
Copy link
Copy link
Closed
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.
Milestone
Metadata
Metadata
Assignees
Labels
acceptedThis proposal is planned.This proposal is planned.proposalThis issue suggests language modifications. If it also has the "accepted" label then it is planned.This issue suggests language modifications. If it also has the "accepted" label then it is planned.
Type
Fields
Give feedbackNo fields configured for issues without a type.
EDIT
&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[*]nullpointer 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.[]nullpointer 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]nullpointer 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[*].[]nulland[N]nullimplicitly cast to[*]null.&ptr[x]and&fooalways gives a^.ptr[x..y]with comptime known x and y gives a[N].array[x..]gives a[N].new array syntax
Now it is clear whether you should do
&arrayor&array[0]. Don't use&array. If you want a[N]T, e.g. a pointer with comptime known length, usearray[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.This paves the way for #733
See also #386
See also #568