4 ms·
> In rust and zig this code will produce a runtime error if you screw up, but in c it's easy to forget to check the tag and then you get UB. As pointed out els
by tsimionescu 6y ago
> In rust and zig this code will produce a runtime error if you screw up, but in c it's easy to forget to check the tag and then you get UB.
As pointed out elsewhere, somewhat surprisingly, this is not UB in C, though it is in C++. In C it is merely unspecified behavior, but perfectly safe if intended.
- jamii 6y agoMy bad, should have verified first.