char * ptr;long sum;...sum += (unsigned int) (((unsigned long)*ptr<<8)|*(ptr+1));
Is it somehow different from sum += *(unsigned int*)ptr; Which is plenty ugly enough already.
Quote from: bill2009 on Apr 24, 2013, 09:58 pmIs it somehow different from sum += *(unsigned int*)ptr; Which is plenty ugly enough already.Not much different. The intent is to ensure the byte ordering. With your expression, the byte ordering depends on the compiler / architecture. With the other expression, the byte order is always the same (presumably "network order").The (unsigned long) cast is strange. Seems rather pointless given the facts that the value can never exceed 16 bits and it is followed by the (unsigned int) cast. Oh well.