Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Q_UNLIKELY and compiler optimization
If I put a function call inside
Q_UNLIKELYcan I be sure that it won't be optimized out? Am I gaining the cache branching reduction one'd expect this way, or it's better to use a variable? E.g.
if (Q_UNLIKELY(myfunction() != SUCCESS)) ; // Do stuff
or should I use:
register int result = myfunction(); if (Q_UNLIKELY(result != SUCCESS)) ; // Do stuff
What is the value of success ? Depending on it you can use
Q_LIKELYbut in any case AFAIK, it won't be optimized out.
Successis equal to zero. I'm not expecting
MPI_Iprobe(the function in question) to ever return an error, unless something is very wrong with a node. However the constant is external to my application and while it's value probably won't change I can't be certain of it.
That's the kind of constant that shouldn't change. Usually success = 0 and anything else (usually below 0) is an error code. Sometimes a positive number can be an information like the size of something.
I'd go for the first version of your if in case you have doubts that SUCCESS might change