Apologies to Edgar Dijkstra: Go To Statement Considered Harmful
The below has been at least mentioned a few times on 'Freaks over the years...
(1<<bitnumber) is now the accepted method to write e.g.
as in the current thread http://www.avrfreaks.net/forum/t...
As AVR8 compilers matured, it turns into an SBI:
TIFR0|=(1<<TOV0); 000000AB SBI 0x15,0 Set bit in I/O register
...and thus CodeVision's "dot" extension e.g. TIFR0.TOV0 is forever condemned to the fires of damnation. But I digress...
Now, experienced 'Freaks know that the OP in the other thread really "meant" to write
TIFR0 = (1<<TOV0);
Running the above fragment in Studio 6.2 simulator, only TOV0 flag got cleared and not OCF0A or OCF0B. Expected with the SBI.
BUT -- the code writer said to the compiler: "Get the contents of volatile [I/O register] TIFR0, OR with 1, and write the result back". That is not the generated code, is it? A very dark and hidden corner in AVR8 world. Should it be changed? Probably not. But is it "conforming to the C standard?" You make the call.
Even better (or worse, depending on your point of view): Consider the explicit RMW; the generated code is still a single SBI:
TIFR0 = TIFR0 | (1<<TOV0); 114: a8 9a sbi 0x15, 0 ; 21
Right or wrong?
 In poking at the above I couldn't really think of a real-world example. "Volatile" to my past lives was something like a memory-mapped peripheral where read/write strobes could cause something to happen.
But back to my timer0 example above. If the above for a single-bit is OK, then what if one wants to clear two out of the three bits? [from the screen shots in the other thread you can see that all three bits are set.]
104: 93 e0 ldi r25, 0x03 ; 3 ... TIFR0 = (1<<TOV0) | (1<<OCF0A); 118: 95 bb out 0x15, r25 ; 21 TIFR0 |= (1<<TOV0) | (1<<OCF0A); 11a: 85 b3 in r24, 0x15 ; 21 11c: 83 60 ori r24, 0x03 ; 3 11e: 85 bb out 0x15, r24 ; 21 TIFR0 = TIFR0 | (1<<TOV0) | (1<<OCF0A); 120: 85 b3 in r24, 0x15 ; 21 122: 83 60 ori r24, 0x03 ; 3 124: 85 bb out 0x15, r24 ; 21
Now my head hurts. More than one bit and |= does a RMW, but not for a single bit. I have no idea what is right or wrong.