How to assign optional tag

@dimdin

You’re triggering undefined behavior with that code, branching on a value of undefined. In my case I’m trying to write a well-defined program.

@LucasSantos91

I wouldn’t say so. It’s a common pattern in Zig to get a pointer to uninitialized data and assign to it later (see Allocator.create(), etc). In fact, the langref explicitly acknowledges the usefulness of this pattern—it’s under “To change the active field of a union when a meaningful value for the field is not known, use undefined”

2 Likes