Date: Wed, 19 Mar 2003 06:25:44 +0200 From: "Eli Zaretskii" Sender: halo1 AT zahav DOT net DOT il To: djgpp AT delorie DOT com Message-Id: <4331-Wed19Mar2003062544+0200-eliz@elta.co.il> X-Mailer: emacs 21.3.50 (via feedmail 8 I) and Blat ver 1.8.9 In-reply-to: <20030318223107.25581.00000232@mb-dh.aol.com> (dang2015@aol.com) Subject: Re: "pragma pack" question References: <20030318223107 DOT 25581 DOT 00000232 AT mb-dh DOT aol DOT com> Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk > 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.