I am wondering about this because of scope issues. For example, consider the code
typedef struct {
int x1;/*top*/
int x2;/*bottom*/
int id;
} sub
I do not agree and NOT RECOMMEND to return vector to change values: Is much faster pass as reference:
void vectorial(vector a, vector b, vector &c)
{
c[0] = a[1] * b[2] - b[1] * a[2]; c[1] = -a[0] * b[2] + b[0] * a[2]; c[2] = a[0] * b[1] - b[0] * a[1];
}
//This is slow!!!:
vector vectorial(vector a, vector b)
{
vector c{ a[1] * b[2] - b[1] * a[2], -a[0] * b[2] + b[0] * a[2], a[0] * b[1] - b[0] * a[1] };
return c;
}
I tested on VS2015 with following results in release mode:
By reference:8.01 MOPs and returning vector: 5.09 MOPs 60% worse!
In debug mode things are much worse:
By reference:0.053 MOPS and return vector: 0.034 MOPs