Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: move field declaration align syntax to field name #5640

Open
Snektron opened this issue Jun 20, 2020 · 1 comment
Open

Proposal: move field declaration align syntax to field name #5640

Snektron opened this issue Jun 20, 2020 · 1 comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@Snektron
Copy link
Collaborator

In the current Zig grammar, fields declarations can be forced to arbitrary alignment by using the align attribute:

const value align(4) = false;

When an explicit type is given, the align is specified after the type:

const value: bool align(4) = false;

With this grammar, it looks like align is actually part of the type expression, which led me to falsely believe that

const A = struct { x: u32 } align(4);

is valid syntax.
I propose to instead place the align attribute after the type name to improve readability:

const value align(4): bool = false;

Another option would be to actually move the align specifier to the type expression, and have TypeName align(expr) be valid syntax. I think in that case it would be clearer to have the alignment before the type name though:

const value: align(4) bool = false;
const A = align(4) struct { x: u32 };
@Vexu Vexu added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Jun 20, 2020
@Vexu Vexu added this to the 0.7.0 milestone Jun 20, 2020
@Snektron
Copy link
Collaborator Author

Snektron commented Jun 20, 2020

I realized there is a similar problem with linksection, as it is currently also specificed after the type.

As for readability, someone commented about this being less readable because the attributes are now specified before the type. A solution to that would be to leave the attributes behind the type, but add some syntax to be able to more clearly separate where the type ends and where the attribute starts, which is also proposed in #5239 and #4285.

@andrewrk andrewrk modified the milestones: 0.7.0, 0.8.0 Oct 26, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 May 19, 2021
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 Nov 23, 2021
@andrewrk andrewrk modified the milestones: 0.10.0, 0.11.0 Apr 16, 2022
@andrewrk andrewrk modified the milestones: 0.11.0, 0.12.0 Apr 9, 2023
@andrewrk andrewrk modified the milestones: 0.13.0, 0.12.0 Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

3 participants