I want to understand this syntax to fix it for crc16 function :
unsigned short crc16(void *memptr, int len) {
int j;
unsigned short crc = CRC16_INIT ;
while(len--){
crc ^= *((unsigned char *)memptr)++;
for(j=0; j<8; j++){
if(crc & 1)
crc =(USHORT)( (crc>>1) ^ CRC16_POLY );
else
crc =(USHORT)( crc>>1);
}//for
}//while
return crc ;
}
it was working code on older compiler and now I ‘ve got
error : IntelliSense: expression must be a modifiable lvalue
on this line:
crc ^= *((unsigned char *)memptr)++;
Compiler error : error C2105: ‘++’ needs l-value
Recoded to it (hope it’s correct):
unsigned char oldValue = *((unsigned char *)memptr);
++*((unsigned char *)memptr);
crc ^= oldValue; // <--- WRONG
crc ^= (*((unsigned char *)memptr))++; // <--- WRONG
ASM-version of this function (not that optimized, but still 0x59 bytes vs my compiler’s 0x69 of C++ version).
If you are familiar with ASM, it will be enough to understand mentioned C++ code segment and the whole function overall.