cancel
Showing results for 
Search instead for 
Did you mean: 

Compiler and bitfields

lseletron
Associate II
Posted on March 26, 2007 at 18:05

Compiler and bitfields

10 REPLIES 10
luca239955_st
Associate III
Posted on March 26, 2007 at 18:05

zsavov,

it is complex and pretty useless (here) to explain here why the compiler generated one code in one case and another code in the other case: they both work correctly and, from the compiler point of view, that's all there is to know.

To make sure the code works in your application, you have two solutions: either you disable interrupts while you modify this register, or you check the code produced by the compiler and you verify it works directly on the register bit.

Note that your best option is probably to use the syntax

PADR_BITS.BIT_4 = (PADR_BITS.BIT_4) ? 0 : 1;

that will generate the best code for you (check the listing)

@woro: my first example was not intended to toggle the bit, it was just a bunch of lines to show how the compiler traslates some instructions. Maybe I should have done a better example..

Regards,

Luca