On Tue, 2008-11-11 at 12:16 -0600, David Kelly wrote: > You use 224UL in your expression and wonder why the comparison is > promoted to 32 bits? The comparison is always the size of the biggest > and your cast only sticks to the first item.
Aha! Thanks =) I'm a novice at C (my job is in bioengineering), and didn't understand that casting only applied to the first item. In retrospect, this makes a lot more sense! Thanks for the tips! -Brian > If you want to force it down to a 16 bit comparison you need to force > everything down to 16 bits: > > while(TCNT3<(uint16_t)( benc_period*224UL/255) ); > > But I think it would be best written like this to enforce the desired > evaluation order: > > while( TCNT3 < (uint16_t)( (benc_period*224UL) /255) ) > ; > > The above because I would be concerned the compiler might rearrange the > order and precalculate 224UL/255. Always better safe than sorry. > > On empty while() loops I like to put the semicolon on a separate line > so that the emptiness stands out. > _______________________________________________ AVR-GCC-list mailing list AVR-GCC-list@nongnu.org http://lists.nongnu.org/mailman/listinfo/avr-gcc-list