This is the mail archive of the ecos-discuss@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Question on programming style


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]