[aklug] Re: Bit field portability

From: Michael Fowler <michael@shoebox.net>
Date: Wed Mar 18 2009 - 13:40:20 AKDT

On Tue, Mar 10, 2009 at 02:25:49PM -0800, Christopher Howard wrote:
> Portability question: I want to use bit fields in one part of my C program
> for flags because it is more convenient than shifting/masking. However,
> this online doc I'm reading indicates that bit fields can make programs
> less portable.

There are two potential portability issues you could run into. The
first is endianness, but you said you're dealing with the data entirely
on the same system, so that shouldn't be a problem.

The other problem is that different compilers align and pad structs
differently. This typically only matters if you rely on a struct being
a certain size, say if you're writing it to a file and reading it back.

If you are concerned about portability I would suggest you write a test
suite for your application. Run automated tests on as much as you can,
and design the code to be as compartmentalized as possible to help this.
Then you can run this test suite on each OS you expect to install to and
verify it works the same.

--
Michael Fowler
www.shoebox.net
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Mar 18 13:40:35 2009

This archive was generated by hypermail 2.1.8 : Wed Mar 18 2009 - 13:40:35 AKDT