Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

5
  • In your example _this is stored in memory wherever it is declared, probably in main() somewhere when you declare your instance of A, or maybe it's a temporary. Supposing then that this is how the compiler "really does it", my question would be where does the compiler's "implicit" _this get instantiated? Commented Aug 29, 2014 at 4:02
  • But you sort of answered that with the last line; I guess I was hoping the standard would have some definition for this, becuase it has important implications in cache management, particularly false sharing. Commented Aug 29, 2014 at 4:02
  • 3
    No, this (or _this in the example) is a formal argument, it is not a local variable in main (or any other function) Commented Aug 29, 2014 at 4:50
  • 3
    Where "this" is stored is the sort of thing that the C++ standard deliberately avoids specifying. That way the compiler writer can determine the most efficient implementation for the particular processor and operating system. In practice, it is very likely to be either on the stack or in a register. It is an ephemeral thing - it only needs to exist while the function is executing, and can be deleted as soon as the function returns. Commented Aug 29, 2014 at 12:47
  • in windows x86 cdecl this is stored in ecx register(this is faster, but since ecx is not accessible to C without assembly); with stdcall, it's stored on the stack as actual first(last to be pushed) argument. This allowed microsoft COM components to be usable from both C and c++ without having to use assembly to access this, or to pass this. Commented Feb 23, 2018 at 4:35