Multiple post-increments on a single source line do not act as expected.
#include <stdio.h>
int main( void )
{
unsigned short array[ 3 ] =
{
0xAA11 , 0xBB22, 0xCC33
};
unsigned short value1, value2;
unsigned char index = 0;
value1 = ( array[ index++ ] & 0xFF ) | ( array[ index++ ] << 8 );
value2 = array[ index ];
printf( "value1: %04hX value2: %04hX
" , value1 , value2 );
return 0;
}
The output of the program is:
value1: 1111 value2: CC33
Expected output:
value1: BB11 value2: CC33
index IS incremented twice as expected, but the unincremented value is used in
BOTH array references.
I get the expected output with BC 3.1.
Bug or bad programming practice? (no need to post a work-around)