Hacker News

Favorites Setup
Comment by bennettnate5 | original | C for Rust programmers
[−]bennettnate5 · 2026-10-10 Sat 18:25 UTC · link
Some fun quirks I never learned until years after first getting into C:

- zero-initialization via `= {0};` will still leave padding and any data not covered by the smallest elements of unions uninitialized, so serializing data structures zeroed via that method is unsafe

- A pointer that increments any more than 1 past the end of a valid memory region (e.g. the end of a buffer) is instant undefined behavior even if the pointer is never dereferenced

- strict aliasing is on by default for pointers of differing types, but not for void/char/uchar. This means that having `struct sockaddr` and `struct sockaddr_in` pointers pointing to the same struct is UB.

The more I learn, the more I run from C.

[−]teo_zero · 2026-10-11 Sun 07:13 UTC · link
> zero-initialization via `= {0};` will still leave padding and any data not covered by the smallest elements of unions uninitialized

You really should move to C23 and use ={}.