Earlier quoted context omitted.
Please explain how you send a struct over the network without UB and leaking the padding.
By knowing its exact size with sizeof(), and using that and a cast to uint8_t* to both bzero() it out before use and memcpy()ing it when sending it. Unless the C standard says that the compiler may change the padding bytes of the existing storage?
struct st s;
bzero(&s, sizeof(s));
// ...
write(fd, &s, sizeof(s));
I’ve dealt with many systems that have tons of unnecessary serialization logic, and found them slower and buggier than just letting the C spec define the data format.Having said that, it is possible to get this sort of thing right with C++ and templates (thanks to inlining).
Higher-level languages without compile time code generation (like Java and Python) usually make serialization a train wreck in comparison with “send raw structs” or “make the [C++] compiler generate and typecheck the machine code that does the serialization”