0

I have the following function:

inline int f(int &x, int y, int z) {
    /* does stuff and changed the value of x at the end */
}

inline int f_p(int * const x, int y, int z) {
    /* exactly the same as f, except replace x with *x */
}

Is there any case in which gcc 4.9 will be able to optimize better a loop that calls f over and over again better than the same loop with a call to f_p instead?

tohava
  • 5,344
  • 1
  • 25
  • 47
  • 3
    Try it and see? The reference version has an immediate advantage in that the compiler does not need to allow for a null pointer. – M.M Nov 22 '15 at 21:42
  • @M.M - null pointers are undefined behavior anyway – tohava Nov 22 '15 at 21:44
  • @M.M - Also, just tried it with a simple example, and got the exact same code. However, my real code is more complicated, and there may be something that I haven't foreseen in how gcc works. Therefore, I am leaving this question alive for now. – tohava Nov 22 '15 at 21:48
  • If care about inlining particular function you can just force its inlining: http://stackoverflow.com/questions/8381293/how-do-i-force-gcc-to-inline-a-function – fghj Nov 23 '15 at 07:57

0 Answers0