Created
February 13, 2025 04:08
-
-
Save wowotek/de23a0250b17b2384dd70c4a29bfd7c4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const eEnumUntyped = enum { | |
val1, | |
val2, | |
val3, | |
val4 | |
}; | |
const eEnumTyped = enum (u32) { | |
val1, | |
val2, | |
val3, | |
val4 | |
}; | |
const sObject = struct { | |
prop_untyped: eEnumUntyped, | |
prop_typed: eEnumTyped | |
}; | |
pub fn main() !void { | |
var objects: [2]sObject = undefined; | |
objects[0] = sObject{ | |
.prop_untyped = eEnumUntyped.val3, | |
.prop_typed = eEnumTyped.val2 | |
}; | |
std.debug.print("object 0 : {} {} \n", .{objects[0].prop_untyped, objects[0].prop_typed}); | |
std.debug.print("object 1 : {} {} \n", .{objects[1].prop_untyped, objects[1].prop_typed}); | |
} |
@thecodingend I forgot i posted this question, i also forget where i post the context for this question. ahhahahaha
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
updated version with
@intFromEnum
, current version panics, thank you for sharing this!