error C2105: '++' needs l-value
sum = sum + *((word16 *) addr)++;
#include <stdio.h> // Needed for printf() #include <stdlib.h> // Needed for rand() //----- Type defines ---------------------------------------------------------- typedef unsigned char byte; // Byte is a char typedef unsigned short int word16; // 16-bit word is a short int typedef unsigned int word32; // 32-bit word is an int //----- Defines --------------------------------------------------------------- #define BUFFER_LEN 6 // Length of buffer //extern char data[6]; char data[6]="CM00"; //----- Prototypes ------------------------------------------------------------ word16 checksum(char *addr, word32 count); //===== Main program ========================================================== int tarun(void) { //byte buff[BUFFER_LEN]; // Buffer of packet bytes word16 check; // 16-bit checksum value word32 i; // Loop counter // Load buffer with BUFFER_LEN random bytes for (i=0; i<BUFFER_LEN; i++) { //buff[i] = (byte) rand(); data[i]=(byte) rand(); } // Compute the 16-bit checksum //check = checksum(buff, BUFFER_LEN); check = checksum(data, BUFFER_LEN); // Output the checksum printf("checksum = %04X \n", check); } //============================================================================= //= Compute Internet Checksum for count bytes beginning at location addr = //============================================================================= word16 checksum(char *addr, word32 count) { register word32 sum = 0; // Main summing loop while(count > 1) { sum = sum + *((word16 *) addr)++; count = count - 2; } // Add left-over byte, if any if (count > 0) sum = sum + *((byte *) addr); // Fold 32-bit sum to 16 bits while (sum>>16) sum = (sum & 0xFFFF) + (sum >> 16); return(~sum); }
char data[6]="CM00";
const char data[6]="CM00";
word16 * waddr = (word16 * ) addr; // Main summing loop while(count > 1) { sum = sum + *waddr++; count = count - 2; }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)