C++ compiler: Is it safe to assume 'this' is passed to member function as a last argument on stack



Hi,

As far as I remember, the C++ standard does not explicitly specify how
'this' should be passed to member function. Further, a quick test
shows the microsoft compiler passes it in register, not on stack.

On the other hand, on our PPC cards, 'this' seems to be passed on
stack, which allows us to use static and non-static functions
interchangeably.
For example:
class C
{
public:
static void doSomething(C* c);
void anotherSomething();
};

and then for void (*func_type)(C* c);

C c;
func_type f=; // here f assigned to 'doSomething' or
'anotherSomething'

f(&c);

BTW, the microsoft compiler does not allow assignment of non-static
member without pretty ugly casting.
We are using Workbench 3.0 and G++ compiler.

The question is how safe it is and may we assume that all G++
compilers that come with Workbench will compile the code similarly?
Specifically, if on PPC it works, may we assume it will work the same
way on MIPS?

Thank you,
Yakov
.



Relevant Pages