Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> That, combined with structs, unions, and it's basic data types allow you to use it for virtually ANY protocol.

Sadly, when you use C to implement low-level binary wire protocols, you quickly discover that structs, bit-fields, and unions are nearly useless because they are incompletely defined. Byte order is undefined. Structure layout is mostly undefined -- you pick field order, but you can't choose packing, alignment, or padding rules. The sizes of the integer types vary by platform and compiler. Bit field layout, packing, and alignment are almost completely undefined.

What you're left to work with are unsigned characters, pointers, and bitwise operations. You have to pack and unpack everything manually, or your code won't port. It's enough to get the job done, but it's like using a wrench to pound in screws.

I could do with a little less specificity of action, myself.



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

Search: