string issues again [modified]
-
Hello again :) Please someone explain me next situation I have next code :
...
const UINT SIZE = 5;TCHAR strDest\[SIZE\]; LPCTSTR strSource = \_T("cool"); \_tcscpy\_s(strDest,sizeof(strDest)/sizeof(TCHAR), strSource); CString s(strDest); MessageBox(s);
...
Everything works fine, but I get some differences in Debug and Release builds. Specifficaly, in Release build, in debugger when I look at contents of
strDest
after_tcscpy_s
function, I see that, first 4 bytes of it are occupied by come strange characters and 5th byte is'c'
, but anyway the resule is displayed correctly in Message box. In Debug build everything happens as expected : first 4 bytes are occupied by'c' 'o' 'o' 'l'
and 5th byte is '\0' Why is this difference ? thank you. I have VS2005 -- modified at 14:21 Friday 2nd June, 2006 -
Hello again :) Please someone explain me next situation I have next code :
...
const UINT SIZE = 5;TCHAR strDest\[SIZE\]; LPCTSTR strSource = \_T("cool"); \_tcscpy\_s(strDest,sizeof(strDest)/sizeof(TCHAR), strSource); CString s(strDest); MessageBox(s);
...
Everything works fine, but I get some differences in Debug and Release builds. Specifficaly, in Release build, in debugger when I look at contents of
strDest
after_tcscpy_s
function, I see that, first 4 bytes of it are occupied by come strange characters and 5th byte is'c'
, but anyway the resule is displayed correctly in Message box. In Debug build everything happens as expected : first 4 bytes are occupied by'c' 'o' 'o' 'l'
and 5th byte is '\0' Why is this difference ? thank you. I have VS2005 -- modified at 14:21 Friday 2nd June, 2006The first 4 bytes of a CString are taken up by an DWORD (unsigned long) that holds the size of the buffer. You should see that in both the Debug and Release builds, but the Debugger may move the pointer to the first part of the character buffer when it is built in Debug. If you check the memory at &strDest, you should see similar results for both. Also, if you intend to place the results of 1 CString into another, you don't need a character buffer. If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac
-
Hello again :) Please someone explain me next situation I have next code :
...
const UINT SIZE = 5;TCHAR strDest\[SIZE\]; LPCTSTR strSource = \_T("cool"); \_tcscpy\_s(strDest,sizeof(strDest)/sizeof(TCHAR), strSource); CString s(strDest); MessageBox(s);
...
Everything works fine, but I get some differences in Debug and Release builds. Specifficaly, in Release build, in debugger when I look at contents of
strDest
after_tcscpy_s
function, I see that, first 4 bytes of it are occupied by come strange characters and 5th byte is'c'
, but anyway the resule is displayed correctly in Message box. In Debug build everything happens as expected : first 4 bytes are occupied by'c' 'o' 'o' 'l'
and 5th byte is '\0' Why is this difference ? thank you. I have VS2005 -- modified at 14:21 Friday 2nd June, 2006Looks like that this is bug in visual studio debugger This strange symbols are nothing else than the pointer to the "cool" string in your resource section(.rdata usually) of executable. In debugger window you see destination buffer address decremented by 4 bytes. I don't know why this happens, but I think that this is bug.