2

I am reading some code and I found the following expression:

Eigen::Matrix< simFloat, 3, 1> rpyTorque(kp_att*(_tkCommands.roll - rpy(0)) - kd_att*(rpyRate(0)),
        kp_att*(_tkCommands.pitch - rpy(1)) - kd_att*(rpyRate(1)),
        _kp_yaw*(_tkCommands.yaw - rpyRate(2)));  

I want just to know if this allocates the variable rpyTorque or something else. My question comes from the thing that I would have done it in this way:

Eigen::Matrix< simFloat, 3, 1> rpyTorque = 
(kp_att*(_tkCommands.roll - rpy(0)) - kd_att*(rpyRate(0)),
kp_att*(_tkCommands.pitch - rpy(1)) - kd_att*(rpyRate(1)),
p_yaw*(_tkCommands.yaw - rpyRate(2)));  

Which is the difference between the 2 solutions? If there is any of course.

Thanks for your help.

desmond13
  • 2,106
  • 2
  • 21
  • 30
  • I think there should be no difference. But I want to be sure. :) – desmond13 Dec 09 '14 at 15:52
  • 1
    Doesn't the second version need to declare the right side as an object of type `Eigen::Matrix`? Also, possible duplicate of [this question](http://stackoverflow.com/questions/2722879/calling-constructors-in-c-without-new) – DaaaahWhoosh Dec 09 '14 at 16:00
  • @DaaaahWhoosh I think it is an actual duplicate of that question, and the answer has little to do with eigen. That being said, the answer could use a refresh with RHR and explaining the difference between the compiler using RVO in a constructor (which was the only old mechanism to optomize) to using move constructors (which the compiler could and will do in some cases) in c++11... – IdeaHat Dec 09 '14 at 16:24
  • 1
    @IdeaHat Well, good luck explaining all that then, because I know I can't :) – DaaaahWhoosh Dec 09 '14 at 16:27

0 Answers0