EGCS: pointer to member functions.

Mike Stump mrs@wrs.com
Wed Jun 30 15:43:00 GMT 1999


> Date: Tue, 15 Jun 1999 06:28:16 +0000
> From: Brendan Simon <brendan@dgs.monash.edu.au>
> To: egcs mailing list <egcs@egcs.cygnus.com>

> egcs-1.1.2 powerpc-linux-crosscompiler, RedHat 5.2 Linux.

> I decided that the FSM actions would be member funtions of an FSM
> class.  I had a look at the generated assembly and am quite
> astonished at the code that is generated.  Why is there so much
> overhead in calling a function via a pointer as apposed to calling
> it directly ?

Because 20 years from now, someone will reuse your code, and use
multiple inheritance and virtual member functions and other such neat
features and they will expect the code to just work.

A member function is not a C function, it is a proper superset.  If
you want just a simple function, use a static member function, and
pass it the this pointer as the first argument.

Welcome to C++.



More information about the Gcc mailing list