Yahoo Groups archive

Lpc2000

Index last updated: 2026-04-28 23:31 UTC

Message

Re: Bit-fields are brain-dead (was Looking to buy compiler)

2005-11-10 by brendanmurphy37

Dan,

I take your point: if a compiler vendor has taken the trouble to 
provide an easy-to-use and readable mechanism to access h/w 
registers, then why not use it? Good point.

If you're happy to stick with one vendor, that's fine. However, be 
very aware that if you ever have to move the code to a different 
compiler for whatever reason, you will be faced with a **lot** of 
verification with an existing or modified set of bit-fields - see 
another reply of mine on this topic.

I don't think it accidental that commercial compiler vendors 
implement this stuff in the way that do. It enables them to 
claim "easy support of target hardware". Don't get be wrong: this 
claim is true, and it will save you time and effort. It also happens 
to be extremely non-portable (to another compiler). Just be aware....

By the way, I don't buy the "h/w access is always non-portable" 
argument for this one: it is perfectly possible to write pure 
ANSI 'C' code hardware drivers that are both correct and readable and 
will compile on any compiler. Using bit-fields is not the way I'd 
choose to do it however.

Brendan

--- In lpc2000@yahoogroups.com, "Dan Beadle" <dan.beadle@i...> wrote:
>
> Charles, I know you have said this before, but I disagree, IF the 
bit
> fields are supplied by the compiler vendor.  Both IAR and KEIL 
provide
> bit field definitions for the Philips parts' registers.
> 
>  
> 
> While they occasionally use different names, that is rare (e.g. 
IOSET1
> vs. IO1SET) and is easily fixed with a define.  So they take
> responsibility for endian-ness and making sure the bits line up.
> 
>  
> 
>  
> 
> Using bit fields makes the code much more readable than constants 
like
> 0x00040000.  You can use notation like #define regbit (1<<18), but 
that
> is not as clear as IO0SET_bit.P0.18.  (did I do the shift right - 
err
> left - correctly to get bit 18? Is the constant 0x00040000 correct 
for
> bit 18?).... 
> 
>  
> 
> We used to hear the same things about writing in c - real 
programmers
> write in assembler.  Now it is real programmers don't use bit 
fields.  
> 
>  
> 
> Bit fields are a tool.  Know how to use the tool and it can save 
time.
> Even if I had to redefine the bit field defines to move to another
> compiler, I think it is worth it.
> 
>  
> 
> My two cents.
> 
>  
> 
> Dan
> 
>  
> 
>  
> 
>   _____  
> 
> From: lpc2000@yahoogroups.com [mailto:lpc2000@yahoogroups.com] On 
Behalf
> Of Charles Manning
> Sent: Wednesday, November 09, 2005 10:13 AM
> To: lpc2000@yahoogroups.com
> Subject: Re: [lpc2000] Bit-fields are brain-dead (was Looking to buy
> compiler)
> 
>  
> 
> 
> > Just to add to the 'never use bit-fields advice', here's an 
article
> > I found a while ago (where the author calls bit-fields brain-
dead) ...
> 
> I would refine this:
> 
> Never use them for anything that does hardware accesses or has 
hardware 
> dependencies.
> 
> I use them quite a bit for packing data into software structures 
because
> this 
> allows me to do bit-wise packing without writing a whole bunch of
> shifter 
> code. Being able to bit-pack structures easily can save a lot of 
space
> when 
> creating large numbers of them.
> 
> 
> 
> 
> 
> 
> SPONSORED LINKS 
> 
> Microprocessor
> <http://groups.yahoo.com/gads?
t=ms&k=Microprocessor&w1=Microprocessor&w2
> 
=Microcontrollers&w3=Pic+microcontrollers&w4=8051+microprocessor&c=4&s
=9
> 3&.sig=tsVC-J9hJ5qyXg0WPR0l6g>  
> 
> Microcontrollers
> <http://groups.yahoo.com/gads?
t=ms&k=Microcontrollers&w1=Microprocessor&
> 
w2=Microcontrollers&w3=Pic+microcontrollers&w4=8051+microprocessor&c=4
&s
> =93&.sig=DvJVNqC_pqRTm8Xq01nxwg>  
> 
> Pic microcontrollers
> <http://groups.yahoo.com/gads?
t=ms&k=Pic+microcontrollers&w1=Microproces
> 
sor&w2=Microcontrollers&w3=Pic+microcontrollers&w4=8051+microprocessor
&c
> =4&s=93&.sig=TpkoX4KofDJ7c6LyBvUqVQ>  
> 
> 8051 microprocessor
> <http://groups.yahoo.com/gads?
t=ms&k=8051+microprocessor&w1=Microprocess
> 
or&w2=Microcontrollers&w3=Pic+microcontrollers&w4=8051+microprocessor&
c=
> 4&s=93&.sig=1Ipf1Fjfbd_HVIlekkDP-A>  
> 
>  
> 
>  
> 
>  
> 
>   _____  
> 
> YAHOO! GROUPS LINKS 
> 
>  
> 
> *	 Visit your group "lpc2000
> <http://groups.yahoo.com/group/lpc2000> " on the web.
> 	  
> *	 To unsubscribe from this group, send an email to:
> 	 lpc2000-unsubscribe@yahoogroups.com
> <mailto:lpc2000-unsubscribe@yahoogroups.com?subject=Unsubscribe> 
> 	  
> *	 Your use of Yahoo! Groups is subject to the Yahoo! Terms of
> Service <http://docs.yahoo.com/info/terms/> . 
> 
>  
> 
>   _____  
> 
> 
> 
> [Non-text portions of this message have been removed]
>

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.