Skip to content

support pointer arithmetic on pointer to array #2018

Open
@andrewrk

Description

@andrewrk

Similar to #863 (when slicing with a comptime length, result type should be pointer to array), pointers to arrays should support pointer arithmetic. The result type is a pointer to an array with a smaller len, and appropriate alignment. Compile error happens if you go out of bounds.

Ran into this working on https://github.com/andrewrk/zig-general-purpose-allocator/. I correctly used a *align(page_size) [page_size]u8 type, but then had to go back and use the worse option [*]align(page_size) u8 due to not having pointer arithmetic.

In general, users should prefer pointers to arrays when the length is compile time known, and the language should support that preference.

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions