Skip to content

Allow comma-separated field list with single type specifier in struct #5519

@JPGygax68

Description

@JPGygax68

In C/C++, you can write

struct Point {
   float x, y, z;
};

In Zig, you have to write

const Point = struct {
  x: f32, y: f32, z: f32
};

The extra typing required seems like a step backwards, and will be difficult to "sell" to C users.
I propose to go back to using semicolons to separate declarations within structs, and allowing commas to chain fields of the same type.

const Point = struct {
  x, y, z: f32;
};

This would make all the more sense given Zig's excellent feature of letting the compiler decide the layout of structs: declare your struct members in the order that's easiest to read, without worrying about wasted bytes.

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

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions