News for hackers. Stuff that matters.
Re:Zig in 30 Minutes by NieDzejkob on Sunday January 03, 2021 @08:54AM (#25621765)
> You can explicitly choose to leave it undefined if it will get set later, but zig will error if you try to use it.

That doesn't seem to be true. The example below this sentence errors because the function foo being used doesn't exist, not because the variable is undefined. A proper example [1] shows that Zig will happily use uninitialized memory here:

    x: -1431655766
[1]: https://godbolt.org/z/36j4ab
Re:Zig in 30 Minutes by dilap on Sunday January 03, 2021 @09:45AM (#25622034)
Yes, you're right. From the manual:

> [Once a variable is set to undefined], it is no longer possible to detect that the value is undefined. undefined means the value could be anything, even something that is nonsense according to the type. Translated into English, undefined means "Not a meaningful value. Using this value would be a bug. The value will be unused, or overwritten before being used."

> In Debug mode, Zig writes 0xaa bytes to undefined memory. This is to catch bugs early, and to help detect use of undefined memory in a debugger.

https://ziglang.org/documentation/master/#undefined