I have some code that has recently been 'ported' to VS. What follows is the statement and the assembler generated, hopefully the 'error' is obvious. Of course the way it has generated this code may be a feature of VS, but I can't say I've seen this before.
switchcount = (int) (*d++) + (*d++<<8) + (*d++<<16) + (*d++<<24);
00A722F6  mov         eax,dword ptr [d]  
00A722F9  movzx       ecx,byte ptr [eax]  
00A722FC  mov         edx,dword ptr [d]  
00A722FF  movzx       eax,byte ptr [edx]  
00A72302  shl         eax,8  
00A72305  add         ecx,eax  
00A72307  mov         edx,dword ptr [d]  
00A7230A  movzx       eax,byte ptr [edx]  
00A7230D  shl         eax,10h  
00A72310  add         ecx,eax  
00A72312  mov         edx,dword ptr [d]  
00A72315  movzx       eax,byte ptr [edx]  
00A72318  shl         eax,18h  
00A7231B  add         ecx,eax  
00A7231D  mov         dword ptr ds:[0AD8CA8h],ecx  
00A72323  mov         ecx,dword ptr [d]  
00A72326  add         ecx,1  
00A72329  mov         dword ptr [d],ecx  
So the code the compiler has generated is essentially
switchcount = (int) (*d) + (*d<<8) + (*d<<16) + (*d<<24);
d += 4 ;
Can anyone show me how to convince the compiler to generate the correct code?
 
     
     
    