On Thu, 6 Mar 2003 12:33:16 -0500, Mark Stokes wrote: >I've been pulling my hair out about an auto increment problem. I >finally realized the following statement wasn't acting as I expected it >to:
>Unsigned char ReadByte( unsigned int *address ) >{ >unsigned char data; > // Setup read from memory chip (SPI) > E2DISABLE; // End Read operation > // Auto increment address the proper number of bytes > *address++; > return data; >} >I expected the contents of memory that address pointed to be incremented >one. But when I check the .lst file, I get this: >... > E2DISABLE; // End Read operation > 1b88: d2 d3 19 00 bis.b #1, &0x0019 > *address++; > return data; > 1b8c: 4f 4e mov.b r14, r15 ; >... >Nothing came out at all!!! And no warnings. When I changed the line to >read: > // Auto increment address the proper number of bytes > *address += 1; >I got the desired result: > *address += 1; > 1b8e: 9e 53 00 00 inc 0(r14) ; >Is this a bug? >-Mark Stokes Mark *address++ increments the pointer variable 'address' by sizeof unsigned int (the size of the variable 'address' is pointing to) but because 'address' is not used again within the function, the optimizer removes the code. *address += 1 increments the unsigned integer referenced by 'address' by 1. hope this helps. -Bill Knight R O SoftWare