At Wed, 5 Mar 2025 10:54:01 +1100, Rob Pike <robpike(a)gmail.com> wrote:
Subject: [TUHS] Re: Any UNIX With No C In Userland?
The notion that the struct layout must correspond to the hardware device's
layout
Not "must" -- "can".
Of course that's just effectively using the compiler to do the
marshalling -- at compile time.
There are caveats of course -- one can lay out bit flags for a register
in a struct, but one must not make a pointer to such a struct and point
it at the register and expect bit manipulations to work -- even with -O0
you'll probably mess up any attempts to change bits predictably in that
register in ways that the hardware expects.
Of course the same problems occur if you try to point a word-sized
integer, even one with a "volatile" qualifier, at a register and
manipulate its bits with C bitwise expressions.
--
Greg A. Woods <gwoods(a)acm.org>
Kelowna, BC +1 250 762-7675 RoboHack <woods(a)robohack.ca>
Planix, Inc. <woods(a)planix.com> Avoncote Farms <woods(a)avoncote.ca>