Can I be sure that:
class foo {
public:
int x;
void bar(int k) {
x = k;
}
};
foo o;
o.bar(5);
Will be the same as:
class foo {
public:
int x;
};
void foobar(foo& f, int k) {
f.x = k;
}
foo o;
foobar(o, 5);
I know both will set "x" to "k", but can I be sure that they both perform at same speed / generate same asm? Can the compiler optimize methods greater?
Generate the assembler and compare (-S flag for GCC).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With