4 ms·
> For example, if I wanted to read a little endian 32-bit integer value from a byte stream, I could write a function like this But for the longest time people
by jcelerier 6y ago
> For example, if I wanted to read a little endian 32-bit integer value from a byte stream, I could write a function like this
But for the longest time people would basically dump the raw bytes of their structs from / to the network whenever possible, e.g.
struct my_data {
int foo, bar;
float x,y,z;
long dontdothat;
} data;
write_bytes_to_the_network((const unsigned char*) &data, sizeof(my_data));
- johannes1234321 6y agoThis not only leads to the endianess issues, but also alignment/packing. But yes, people often start that way and regret only when it is too late and the files are in the wild.