Wednesday, February 18, 2004

Unicode question

A couple of days ago I wrote a simple function and a part of it looked like this:


CString str;
str.Format(_T("this is only a test"));
int idx = str.Find('o');
if( idx >= 0 )
str = str.Left(idx);

The project have UNICODE defined so when today I reviewed this piece of code it looked wrong because the Find method as a character parameter that is not treated really as an unicode character. However it did compile well (and work too) under Visual C++ 6.

So when I got home I decided I need to understand why it works. I opened my Microsoft Visual C++ .NET 2003 wrote this little test console app and I generated the asm and the results (in debug configuration) are:

 




; 22   :     int idx = str.Find('o');

mov esi, esp
push 0
push 111 ; 0000006fH
lea ecx, DWORD PTR _str$[ebp]
call DWORD PTR __imp_?Find@?$CStringT@GV? (...)
cmp esi, esp
call __RTC_CheckEsp
mov DWORD PTR _idx$[ebp], eax
; 22   :     int idx = str.Find(_T('o'));

mov esi, esp
push 0
push 111 ; 0000006fH
lea ecx, DWORD PTR _str$[ebp]
call DWORD PTR __imp_?Find@?$CStringT@GV? (...)
cmp esi, esp
call __RTC_CheckEsp
mov DWORD PTR _idx$[ebp], eax

So both of them are compiled in the same manner. That's explain why it did compile successfully and why it works but I still doesn't understand why it didn't require the L (or TEXT or _T) macro.

No comments: