You might be right about the ?: operator, but it does not explain everything.
I'm not sure if ?: should return a value or not on it's own (since as
I said I'm no expert in C), it sure can be used as a right value in an
assignment.
It all would be ok, if for example the code said
a= bit_write(PORTA,b,c);
or the function had a
return bit_write(PORTA,b,c);
statement. But it does not.
My other problem with this is, it only "returns a value" when it's
executed indirectly (contained in a function, that provides it's c
parameter as a variable!). For example it does not generate an 'in'
instruction in the main program (function). If you were right about
that ?: should read the volatile twice, then it should happen at the
first bit_write() statement in the main function too.
Also calling a function like this:
static inline void t_BWd(char bit)
{
bit_write(PORTA,bit,0);
}
only generates a 'cbi' but no 'in' instruction.
So something is not right either way.
On Sat, Mar 27, 2010 at 10:02 PM, David Brown <address@hidden> wrote:
Joerg Wunsch wrote:
David Brown <address@hidden> wrote:
Evaluating the result of "p |= BIT(b)" means carrying out the
or-assign, then reading the value of p and returning it.
You're right, I stand corrected.
That's certainly how /I/ interpret the way volatile works in such cases. I
believe there is some uncertainty about how it should work in C++ - the same
statement /may/ have a different interpretation in C and C++ when volatiles
are sort-of read in this way.
All in all, the fact that even experts are not always accurate in such cases
suggests that you should stay well away from such code - an explicit "if" is
clear, works exactly as intended, and in some cases gives noticeably better
code than a logically equivalent "?:" expression.
_______________________________________________
AVR-GCC-list mailing list
address@hidden
http://lists.nongnu.org/mailman/listinfo/avr-gcc-list