just a thought about "doing the compilers job"

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • .rhavin grobert

    just a thought about "doing the compilers job"

    guess you have the following:

    class X {
    int fn1(); // -\ lets assume those fn's
    int fn2(); // >- do something independent
    int fn3(); // -/ from each other
    }

    class Y {
    public:
    X& X() {return m_x;};
    private:
    X m_x;
    };

    class Z {
    public:
    Y& Y() {return m_y;};
    private:
    Y m_y;
    };

    _______________ _______________ _

    now when i do something like this:

    Z z;
    CallWhateverFun ctionTakingThre eInts(z.y().x() .fn1,z.y().x(). fn2,z.y().x().f n3);

    is it as effective as writing ...

    Z z;
    X& x = z.y().x();
    CallWhateverFun ctionTakingThre eInts(x.fn1,x.f n2,x.fn3);


  • Victor Bazarov

    #2
    Re: just a thought about "doing the compilers job"

    ..rhavin grobert wrote:
    guess you have the following:
    >
    class X {
    int fn1(); // -\ lets assume those fn's
    int fn2(); // >- do something independent
    int fn3(); // -/ from each other
    }
    >
    class Y {
    public:
    X& X() {return m_x;};
    private:
    X m_x;
    };
    >
    class Z {
    public:
    Y& Y() {return m_y;};
    private:
    Y m_y;
    };
    >
    _______________ _______________ _
    >
    now when i do something like this:
    >
    Z z;
    CallWhateverFun ctionTakingThre eInts(z.y().x() .fn1,z.y().x(). fn2,z.y().x().f n3);
    >
    is it as effective as writing ...
    >
    Z z;
    X& x = z.y().x();
    CallWhateverFun ctionTakingThre eInts(x.fn1,x.f n2,x.fn3);
    >
    >
    Generally speaking, the compiler is usually smart enough to take
    advantage of inlining of your functions and also to cache the common
    subexpression, so, yes it would be as effective in terms of the program
    performance (if it isn't, you probably want to chuck that compiler and
    get a better one). However, from the readability point of view, the
    latter version is waaaaay better.

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask

    Comment

    Working...