Mail Archives: djgpp/2003/03/18/23:31:42
> From: dang2015 AT aol DOT com (DanG2015)
> Newsgroups: comp.os.msdos.djgpp
> Date: 19 Mar 2003 03:31:07 GMT
>
> As a side note, I read a post where someone said something such
> as "padding hurts portability". I think this is just the opposite; If you
> can control the size of structs, especially with binary I/O ACROSS
> multiple platforms, you enhance portability
Binary I/O of struct's is never portable. If you want to write a
portable program that uses binary I/O, you need to manually insert
bytes from the struct into an array declared `unsigned char', and
swap the bytes to the ``network order'' befopre doing that with
functions `htonl' and `htons'.
> As I said, the output surprised me:
>
> sizeof A = 2
> sizeof B = 2
> sizeof C = 2
> sizeof D = 2
This is expected: `char' entities don't need any alignment, so the
output is unaffected.
- Raw text -