2

In my vtable i found a method that simply returns ecx. Now im confused as to what this tries to accomplish ? Is this a known useful sequence ?

1

The C++ compiler of Visual Studio uses ecx as the default register for this pointer, a virtual method which returns ecx then actually returns this or *this. For example, you can test the following code:

class A
{
public:
  virtual A getmyself() { return *this; }
  virtual A* getmyselfpointer() { return this; }
}

The generated assembly code for getmyself (the same for getmyselfpointer) is

getmyself:
  mov     eax, ecx
  retn

This detail is not true for clang or gcc since they do not use ecx as default register for this.

| improve this answer | |
0

It could be a method that at a high-level is intended to return a covariant object pointer.

| improve this answer | |
0

If it would be ARM I'd say that it is constructor or destructor (see this answer for more details). As a part of more general pattern I had seen such a things in a multi-platform applications where the main code of the function was #ifdef'ed out and only return value was left for compatibility with other platforms/build configurations.

Did you see calls to this function?

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.