The following program shows that wrapping a simple class around a function
pointer costs important optimizations.  If you change the #if 1 to #if 0,
you'll see that the call is completely optimized away.  

#if 1
struct pf
{
  inline pf(int(*x)(int)) : x(x) {}

  inline int operator()(int a) const
  {
    return x(a);
  }

  int (*x)(int);
};
#else
typedef int(*pf)(int);
#endif

inline int g(int x) { return x/x - 1; }

int main(int argc, char* argv[])
{
  pf f(g);
  return f(3);
}


-- 
           Summary: Function object abstraction penalty
           Product: gcc
           Version: 4.4.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: dave at boost-consulting dot com


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=40874

Reply via email to