Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 518845
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T07:58:45+00:00 2026-05-13T07:58:45+00:00

In the CString header file (be it Microsoft’s or Open Foundation Classes – http://www.koders.com/cpp/fid035C2F57DD64DBF54840B7C00EA7105DFDAA0EBD.aspx#L77

  • 0

In the CString header file (be it Microsoft’s or Open Foundation Classes – http://www.koders.com/cpp/fid035C2F57DD64DBF54840B7C00EA7105DFDAA0EBD.aspx#L77 ), there is the following code snippet

struct CStringData
{   
    long nRefs;
    int nDataLength;
    int nAllocLength;
    TCHAR* data() { return (TCHAR*)(&this[1]); };
    ...
};

What does the (TCHAR*)(&this[1]) indicate?

The CStringData struct is used in the CString class (http :// http://www.koders.com/cpp/fid100CC41B9D5E1056ED98FA36228968320362C4C1.aspx).

Any help is appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T07:58:45+00:00Added an answer on May 13, 2026 at 7:58 am

    CString has lots of internal tricks which make it look like a normal string when passed e.g. to printf functions, despite actually being a class – without having to cast it to LPCTSTR in the argument list, e.g., in the case of varargs (...) in e.g. a printf. Thus trying to understand a single individual trick or function in the CString implementation is bad news. (The data function is an internal function which gets the ‘real’ buffer associated with the string.)

    There’s a book, MFC Internals that goes into it, and IIRC the Blaszczak book might touch it.

    EDIT: As for what the expression actually translates to in terms of raw C++:-

    TCHAR* data() { return (TCHAR*)(&this[1]); };
    

    this says “pretend you’re actually the first entry in an array of items allocated together. Now, the second item isnt actually a CString, it’s a normal NUL terminated buffer of either Unicode or normal characters – i.e., an LPTSTR”.

    Another way of expressing the same thing is:

    TCHAR* data() { return (TCHAR*)(this + 1); };
    

    When you add 1 to a pointer to T, you actually add 1* sizeof T in terms of a raw memory address. So if one has a CString located at 0x00000010 with sizeof(CString) = 4, data will return a pointer to a NUL terminated array of chars buffer starting at 0x00000014

    But just understanding this one thing out of context isnt necessarily a good idea.

    Why do you need to know?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array, as below: var cString = [ ['1','Techdirt','www.techdirt.com'], ['2','Slashdot','slashdot.org'], ['3','Wired','wired.com'] ];
I've declared a struct in my header file like this: typedef struct { NSString
CString is quite handy, while std::string is more compatible with STL container. I am
What is the difference between CString in vc6 and vc7?
What is the maximum length in characters a CString object can hold?
Is there any regular expression library that i can use with CString of vc6?
I've got a node struct struct Node{CString text, int id;}; in a sorted vector.
I have two header files named string.h in different libraries, they are conflicted with
How can I convert a BYTE array in a CString in MFC?
If possible one that supports at least spell checking: C# string literals HTML content

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.