This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: Question on programming style
- From: Nick Garnett <nickg at ecoscentric dot com>
- To: Rycerz Roman-G11565 <roman dot rycerz at motorola dot com>
- Cc: "Ecos-Discuss at Sources dot Com (ecos-discuss at sources dot redhat dot com)" <ecos-discuss at sources dot redhat dot com>
- Date: 30 Sep 2004 18:32:40 +0100
- Subject: Re: [ECOS] Question on programming style
- References: <5D454811D0A1D711A12A00065BF36FAD08B9E1B3@il06exm11>
Rycerz Roman-G11565 <roman.rycerz@motorola.com> writes:
> Hi
>
> I was just wondering what the communities feeling about using "bitwise" syntax. That is declaration and use of binary variables
> as would be used in device drivers... seems to me it would be a lot more readable
>
If you mean using C bitfields, I have just one word:
Nooooooooooooooooooooooooooooooooooooooooooooooooo!
Their implementation is entirely undefined in the language. You have
no control over the way in which they are packed into a word. You
don't know even what size of word will be used. You have no idea what
sequence of loads and stores the compiler will generate to access the
fields. You don't know when such accesses will take place, and you
don't know what sizes they might be.
For accessing hardware registers you need to be absolutely clear
exactly when the reads and writes happen, and what sizes they will
be. This is why we have the HAL_READ_UINT32() macro and friends.
Bitfields can only really be used in data structures that will have
absolutely nothing to do with any hardware. Even then I would prefer
to define a flags word and do the shifting and masking myself.
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss