avr-libc-dev
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-libc-dev] Bit number/mask, Part 3000


From: Joerg Wunsch
Subject: Re: [avr-libc-dev] Bit number/mask, Part 3000
Date: Mon, 10 Apr 2006 07:05:49 +0200
User-agent: Mutt/1.5.11

As Vic Wagner wrote:

> It's getting tiresome to keep reminding people that C (and C++, of
> course) has always had a mechanism for dealing with single bits
> (multiple bit fields, too) called, _big surprise_ bit fields go look
> it up on your favorite elementary book on your fave of the two
> languages.

It's tiresome to remind people that bitfields in C are a completely
useless thing when it comes to hardware abstractions, as about
everything about them is implementation-defined so you cannot predict
their behaviour for different compilers.

I've heard that Ada did a better job here.

Also, with bit-fields, it's getting even harder to set unrelated bits
in a single byte at the same time.  As the object they are referring
to is `volatile', the compiler would not be allowed to optimize two
adjacent settings into a single one:

ADCSRA.ADEN = 1;
ADCSRA.ADSC = 1;

while without bitfields, you can have both forms:

ADCSRA = _BV(ADEN) | _BV(ADSC);

or

ADCSRA = _BV(ADEN);
ADCSRA |= _BV(ADSC);

-- 
cheers, J"org               .-.-.   --... ...--   -.. .  DL8DTL

http://www.sax.de/~joerg/                        NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]