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 6251877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T13:41:42+00:00 2026-05-24T13:41:42+00:00

Does using this pointer adds another operation to the program at runtime? Just to

  • 0

Does using “this” pointer adds another operation to the program at runtime?

Just to give an example to explain the question better:

class C
{
public:
    void set_x(int val){ x = val; }
    void set_this_x(int val){ this->x = val; }

private:
    int x;
};

Does the function “C::set_x()”, during runtime, performs 1 less operation than “C::set_this_x()” ?

Thanks! 🙂

  • 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-24T13:41:43+00:00Added an answer on May 24, 2026 at 1:41 pm

    There is no difference between the two member functions. It has to be, since this is what the C++ Standard (ISO/IEC 14882:2003) has to say:

    9.3.1 Nonstatic member functions [class.mfct.nonstatic]

    2. When an id-expression (5.1) that is not part of a class member
    access syntax (5.2.5) and not used to form a pointer to member (5.3.1)
    is used in the body of a nonstatic member function of class X or
    used in the mem-initializer for a constructor of class X, if name
    lookup (3.4.1) resolves the name in the id-expression to a nonstatic
    nontype member of class X or of a base class of X, the
    id-expression is transformed into a class member access expression
    (5.2.5) using (*this) (9.3.2) as the postfix-expression to the left
    of the . operator. The member name then refers to the member of the
    object for which the function is called.

    5.2.5 Class member access [expr.ref]

    3. If E1 has the type “pointer to class X,” then the expression
    E1->E2 is converted to the equivalent form (*(E1)).E2; …

    So that means the following code:

    class C
    {
    public:
        void set_x(int val) { x = val; }
        void set_this_x(int val) { this->x = val; }
    private:
        int x;
    };
    

    would’ve been transformed to the following code according to 9.3.1/2 and 5.2.5/3:

    class C
    {
    public:
        void set_x(int val)      { (*this).x = val; }   // as per 9.3.1/2
        void set_this_x(int val) { (*(this)).x = val; } // as per 5.2.5/3
    private:
        int x;
    };
    

    To show that there really is no difference, at least for one compiler, here’s a side-by-side comparison of the disassembly of the C::set_x() and C::set_this_x() function the VC++ compiler emits with optimizations disabled (/Od):

      void set_x(int val){ x = val; }      void set_this_x(int val){ this->x = val; }
    push      ebp                        push      ebp
    mov       ebp,esp                    mov       ebp,esp
    sub       esp,0CCh                   sub       esp,0CCh
    push      ebx                        push      ebx
    push      esi                        push      esi
    push      edi                        push      edi
    push      ecx                        push      ecx
    lea       edi,[ebp-0CCh]             lea       edi,[ebp-0CCh]
    mov       ecx,33h                    mov       ecx,33h
    mov       eax,0CCCCCCCCh             mov       eax,0CCCCCCCCh
    rep stos  dword ptr es:[edi]         rep stos  dword ptr es:[edi]
    pop       ecx                        pop       ecx
    mov       dword ptr [ebp-8],ecx      mov       dword ptr [ebp-8],ecx
    mov       eax,dword ptr [this]       mov       eax,dword ptr [this]
    mov       ecx,dword ptr [val]        mov       ecx,dword ptr [val]
    mov       dword ptr [eax],ecx        mov       dword ptr [eax],ecx
    pop       edi                        pop       edi
    pop       esi                        pop       esi
    pop       ebx                        pop       ebx
    mov       esp,ebp                    mov       esp,ebp
    pop       ebp                        pop       ebp
    ret       4                          ret       4
    

    Note that the compiler produces the exact same assembly for both member functions.

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

Sidebar

Related Questions

I've just solved another *I-though-I-was-using-this-version-of-a-library-but-apparently-my-app-server-has-already-loaded-an-older-version-of-this-library-*issue (sigh). Does anybody know a good way to verify
I'm using MS Sql 2005. Why does this give me the correct results (returns
does anyone know if you can do something like this using the (N)Hibernate criteria
Why does this code fail to display the category name Apples using the current
I am using WMI to query some properties disk drive. Does WMI read this
The const modifier in C++ before star means that using this pointer the value
I am using a delegate which calls an unmanaged function pointer. This causes the
Does using Multiple .NET Languages (Delphi, VB.NET, C#) into the same application (but in
When does using extension methods make sense? Does adding extension methods to a type
In .NET, under which circumstances should I use GC.SuppressFinalize() ? What advantage(s) does using

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.