I have the following code its an a.cpp file when i compile this code in visaul studio i am getting an error :-
error C2105: '++' needs l-value
at the line
sum = sum + *((word16 *) addr)++;
What should i do to remove the error
#include <stdio.h> // Needed for printf()
#include <stdlib.h> // Needed for rand()
typedef unsigned char byte; typedef unsigned short int word16; typedef unsigned int word32;
#define BUFFER_LEN 6 // Length of buffer
char data[6]="CM00";
word16 checksum(char *addr, word32 count);
int tarun(void)
{
word16 check; word32 i;
for (i=0; i<BUFFER_LEN; i++)
{
data[i]=(byte) rand();
}
check = checksum(data, BUFFER_LEN);
printf("checksum = %04X \n", check);
}
word16 checksum(char *addr, word32 count)
{
register word32 sum = 0;
while(count > 1)
{
sum = sum + *((word16 *) addr)++;
count = count - 2;
}
if (count > 0)
sum = sum + *((byte *) addr);
while (sum>>16)
sum = (sum & 0xFFFF) + (sum >> 16);
return(~sum);
}