When Created: 08/27/1998 21:21:56
Against DJGPP version: 2.01
Abstract: multiple post-increments
Multiple post-increments on a single source line do not act as expected.
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 );
The output of the program is:
value1: 1111 value2: CC33
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)
Note added: 08/27/1998 21:32:21
By whom: firstname.lastname@example.org
Your bug. Such things yield "undefined results"; Borland C just happens to
do what you want.
Solution added: 08/27/1998 22:06:27
Disregard my BUG report. Not only is it a BAD programming practice, but it also
DOES NOT work in BC 3.1 (I thought it did in my original complicated program,
but this streamlined TEST version DID NOT WORK, either).
Closed on 10/13/1998 16:00:38: Non-bug (C understanding problem)
By whom: email@example.com