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

Dude, you lost me at "just use an array and fill it in".

Learn about struct packing and let the compiler fill in the "array" for you.

Anyway, a good way to learn stuff. Hard mode, FTW!




C structure packing isn't portable and doesn't account for host/network endianness. Buffer byte-oriented de/ser is the primary way of assembling data in C.


Yes. For production, struct are obvious choice. But here arrays were similar to how documentation specified data will be on the wire. So for educational purposes (to explain protocol) it seemed like a better choice. But I might be wrong and maybe structs would have been more approachable way to understand.




Consider applying for YC's W25 batch! Applications are open till Nov 12.

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

Search: