C standards and committees (was Re: strangest systems I've sent email from)
Maciej W. Rozycki
macro at linux-mips.org
Sun May 22 12:04:21 CDT 2016
On Sun, 22 May 2016, Mouse wrote:
> >>> First off, the C standard mandates that the order of fields in a
> >>> struct cannot be reordered,
> >> Yes. (I think this is a Bad Thing, but I can see why they did it.)
> > Given that C is a systems implementation language, how would you
> > define HW related data structures where the order of the fields is
> > critical (ie HW defines them).
>
> I can see three answers.
>
> 1) Don't use structs for that. Look at NetBSD's bus-space abstraction
> for one possible way.
>
> 2) Make any reordering implementation-defined, so that code for
> specific implementations can know how the implementation does it.
>
> 3) Make reordering optional. Which way the default should go is
> arguable; since my guess is that most structs are not
> hardware-interface structs, the default should be reordering, with
> some keyword specifying no reordering.
4) While the C language standard may not mandate it itself, a specific
system ABI may require a particular bitfield, structure, etc. layout
which C compiler implementations for that platform need to adhere to,
and then you can rely on that. Of course that does not solve the
problem for code which has to be portable across systems (e.g. option
card drivers), but there you usually need to take extra care for
differences between systems (e.g. endianness) anyway.
Maciej
More information about the cctalk
mailing list