Hacker News new | past | comments | ask | show | jobs | submit login

Zig also has undefined behavior.

See whole section here

https://ziglang.org/documentation/master/#Undefined-Behavior

the difference is, they try to check for them at compile time, and if you compile with safety checks, also at runtime; however, if you compile with ReleaseFast (which I assume most people will in production), those runtime checks are turned off and the undefined behavior still exists.




> (which I assume most people will in production)

No, people are supposed to use ReleaseSafe, especially "in production". You can still disable runtime checks in specific execution paths.

ReleaseFast is for applications where there are no disastrous consequences to a bug in the code, like videogames.


Having your account hacked is a disastrous consequence though. And it's likely that the need of performance is not on the CPU side of things but on the GPU so ReleaseSafe should be good enough.


Oh! I didn't know that. In that case, sorry for mischaracterization.


Right, I hadn't meant to imply Zig is free of UB. It aims to improve on C's wild-west UB rules not by having no UB, but by having only a manageable dose of it, and supporting good optional runtime checks.

Zig's approach is essentially that of Ada. You can ask the Ada compiler for runtime checks, or promise the compiler that your code is free of undefined behaviour and have your code run at the speed of light (C), or go haywire if you got it wrong. Sadly C is less suited to runtime checks, arrays are dealt with through raw pointers so range checks aren't easy for the compiler to add automatically. You can though ask GCC to generate checks (trap-on-failure) for things like dereferencing NULL, or signed arithmetic overflow.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: