Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. string issues again [modified]

string issues again [modified]

Scheduled Pinned Locked Moved C / C++ / MFC
debuggingquestionannouncement
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    big_denny_200
    wrote on last edited by
    #1

    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_sfunction, 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

    Z A 2 Replies Last reply
    0
    • B big_denny_200

      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_sfunction, 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

      Z Offline
      Z Offline
      Zac Howland
      wrote on last edited by
      #2

      The 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

      1 Reply Last reply
      0
      • B big_denny_200

        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_sfunction, 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

        A Offline
        A Offline
        Anton Mikhalyov
        wrote on last edited by
        #3

        Looks 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.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups