flâneur — a map of the web's best reading

Zig: Already More Knowable Than C - Andrew Kelley

andrewkelley.me · 1,436 words · saved by 1 readers

There is a nifty article created back in 2015 that made its way onto Hacker News today: I Do Not Know C. The author creates a delightful set of source code samples in which the reader is intended to determine the correctness, and if correct, predict the output of the provided code. If you have not done the exercises, I encourage you to take a moment to do so. What follows are some of the examples translated into Zig for comparison. The numbers correspond to the numbers from the original post linked above, but the C code is embedded here for comparison. In Zig: Output: When this example is translated to Zig, you have to explicitly decide if the pointer is nullable. For example, if you used a bare pointer in Zig: Then it wouldn't even compile: I think this error message can be improved, but even so it prevents a possible null related bug here. If the code author makes the pointer nullable, then the natural way to port the C code to Zig would be: This compiles to: This does a null check,

Zig: Already More Knowable Than C - Andrew Kelley Andrew Kelley - Zig: Already More Knowable Than C (2017 Feb 14) Zig: Already More Knowable Than C There is a nifty article created back in 2015 that made its way onto Hacker News today: I Do Not Know C . The author creates a delightful set of source code samples in which the reader is intended to determine the correctness, and if correct, predict the output of the provided code. If you have not done the exercises, I encourage you to take a moment to do so. What follows are some of the examples translated into Zig for comparison. The numbers cor

Explore this link on the map →

saved by

related reading