This behavior is observed in version 10.0.40219.1 SP1RelI have this code:#include "stdafx.h"#include <Windows.h>int myStrlenImpl( const char * ptr, int len ){ if( *ptr == 0 ) { return len; } return myStrlenImpl( ptr + 1, 1 + len);}int myStrlen( const char* ptr ){ return myStrlenImpl( ptr, 0 );}int _tmain(int /*argc*/, _TCHAR* /*argv*/[]){ char buffer[100]; strcpy( buffer, "Hello" ); if( myStrlen( buffer ) ) { Sleep( 0 ); } return 0;}I compile it with /O2, run and open the disassembly. Here's what I see:--- c:\pathtofile\source.cpp ---- 8: } 9: return myStrlenImpl( ptr + 1, 1 + len);00401000 jmp myStrlenImpl+7 (401007h) 00401002 inc dword ptr [esp+4] 00401006 inc eax 1: #include "stdafx.h" 2: #include <Windows.h> 3: 4: int myStrlenImpl( const char * ptr, int len ) 5: { 6: if( *ptr == 0 ) {00401007 cmp byte ptr [eax],0 0040100A jne myStrlenImpl+2 (401002h) 7: return len;0040100C mov eax,dword ptr [esp+4] 10: }00401010 ret 11: 12: int myStrlen( const char* ptr ) 13: { 14: return myStrlenImpl( ptr, 0 ); 15: } 16: 17: int _tmain(int /*argc*/, _TCHAR* /*argv*/[]) 18: {00401011 push ebp 00401012 mov ebp,esp 00401014 sub esp,68h 00401017 mov eax,dword ptr [___security_cookie (403000h)] 0040101C xor eax,ebp 0040101E mov dword ptr [ebp-4],eax 00401021 push esi 00401022 push edi 19: char buffer[100]; 20: strcpy( buffer, "Hello" );00401023 mov esi,offset string "Hello" (4020E4h) 00401028 lea edi,[ebp-68h] 0040102B movs dword ptr es:[edi],dword ptr [esi] 0040102C movs word ptr es:[edi],word ptr [esi] 21: if( myStrlen( buffer ) ) {0040102E cmp byte ptr [ebp-68h],0 00401032 pop edi 00401033 pop esi 00401034 je wmain+3Eh (40104Fh) 00401036 push 1 00401038 lea eax,[ebp-67h] 0040103B call myStrlenImpl (401000h) 00401040 add esp,4 00401043 test eax,eax 00401045 je wmain+3Eh (40104Fh) 22: Sleep( 0 );00401047 push 0 00401049 call dword ptr [__imp__Sleep@4 (402000h)] 23: } 24: return 0; 25: }0040104F mov ecx,dword ptr [ebp-4] 00401052 xor ecx,ebp 00401054 xor eax,eax 00401056 call __security_check_cookie (40105Dh) 0040105B leave 0040105C ret --- f:\dd\vctools\crt_bld\self_x86\crt\src\intel\secchk.c ----------------------Note that the first lines in the file are the end of the function, then go the #defines and then the start of the function - in fact the function is split into two parts and interleaved with #defines. Such weird mapping seriously impedes usability.
Visual Studio/Team Foundation Server/.NET Framework Tooling version
Steps to reproduce
Product Language
Operating System
Operating System Language
Actual results
Expected results