3 ms·
A problem for Zig is the combination of unsigned overflow UB, implicit widening and always performing operations on the type size of the operands. For example,
by Nuoji 6y ago
A problem for Zig is the combination of unsigned overflow UB, implicit widening and always performing operations on the type size of the operands.
For example, let’s say you have `a = b + c` with b/c being i8 and a i32. This calculation is first performed as an 8 bit add, then extended to 32 bits. This is true for both Rust and Zig, but Rust requires an explicit cast to widen the result of `b + c`, making it obvious that an extension happens and that `b + c` is not performed in 32 bits. In Zig there is no such indication- you need to look up the definition of b and c. Other problems occur as well, that both C and Rust avoid in their own ways. Hopefully Zig can improve this situation.
See more here: https://c3.handmade.network/blogs/p/7651-overflow_trapping_in_practice#23988 https://c3.handmade.network/blogs/p/7651-overflow_trapping_i...