You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The langref mentions pointer arithmetic, and contains a test stating in a comment that ptr[start..] == ptr + start.
However, while the semantics seem perfectly clear, the language arbitrarily disallows the second variant if @sizeOf(ptr[0]) == 0 by compile error.
Test case:
.zig:13:13: error: pointer arithmetic requires element type 'u0' to have runtime bits
_ = ptr + 4; //compile error if @sizeOf(E) == 0
~~~~^~~
referenced by:
decltest.f: .zig:3:6
.zig:13:13: error: pointer arithmetic requires element type 'void' to have runtime bits
_ = ptr + 4; //compile error if @sizeOf(E) == 0
~~~~^~~
.zig:13:13: error: pointer arithmetic requires element type 'type' to have runtime bits
_ = ptr + 4; //compile error if @sizeOf(E) == 0
~~~~^~~
Expected Behavior
Imo the language would be more consistent if we allowed the pointer-arithmetic variants for all element types. ptr + offset has well-defined semantics exactly equivalent with ptr[offset..].
The fact that the comment in the langref agrees with me made me think this limitation was unintentional.
Now that I wrote this all out I guess it might be seen as a proposal - I'll let someone else decide which label fits better,
The text was updated successfully, but these errors were encountered:
rohlem
added
the
bug
Observed behavior contradicts documented or intended behavior
label
Sep 14, 2024
rohlem
changed the title
[*] inconsistent with [N]: compile error "pointer arithmetic requires element type 'void' to have runtime bits"([*]E) + N inconsistent with ([*]E)[N..]: compile error "pointer arithmetic requires element type 'void' to have runtime bits"
Sep 14, 2024
Zig Version
0.14.0-dev.617+208baa37c
Steps to Reproduce and Observed Behavior
The langref mentions pointer arithmetic, and contains a test stating in a comment that
ptr[start..] == ptr + start
.However, while the semantics seem perfectly clear, the language arbitrarily disallows the second variant if
@sizeOf(ptr[0]) == 0
by compile error.Test case:
compiler output:
Expected Behavior
Imo the language would be more consistent if we allowed the pointer-arithmetic variants for all element types.
ptr + offset
has well-defined semantics exactly equivalent withptr[offset..]
.The fact that the comment in the langref agrees with me made me think this limitation was unintentional.
Now that I wrote this all out I guess it might be seen as a proposal - I'll let someone else decide which label fits better,
The text was updated successfully, but these errors were encountered: