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

std: use decl literals to improve endian ergonomics #23103

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

nektro
Copy link
Contributor

@nektro nektro commented Mar 5, 2025

also uses enhancement to deprecate std.mem.{read,write}PackedInt{Native,Foreign}

@@ -813,6 +813,9 @@ pub const FloatMode = enum {
pub const Endian = enum {
big,
little,

pub const native = builtin.target.cpu.arch.endian();
pub const foreign: Endian = @enumFromInt(1 - @intFromEnum(native));
Copy link
Contributor

@GrayHatter GrayHatter Mar 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure this is only valid as long as mixed endian is never added. Also, translating from an enum to an int, just to go back to an enum feels kinda weird. Why not if (native == .big) .little else .big

Otherwise, I'm a fan I wished for .native, just this morning.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mixed-endian CPUs aren't really a thing, but even if they were, there are more fundamental issues to solve such as what to do about packed structs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not if (native == .big) .little else .big

Better yet: put that in a function Endian.flip (or Endian.invert or something idk) and call it here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would that be necessary outside right here?

@marler8997
Copy link
Contributor

Clever. I didn't realize decl literals kinda give you the ability to add enum value aliases. This is a problem for zigwin32 because there are many enums that have value conflicts (multiple names for the same value). Before your PR I was just adding comments for each conflicting value but I've updated them to be added as declarations instead (marlersoft/zigwin32@7b434a4).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants