jeudi 28 janvier 2016

Function return in branches of an `if` vs outside the `if`, in C++

Are there differences in the compiled code between

double func(bool x) {
  if (x) {
    return 1.0;
  } else {
    return 2.0;
  };
}

and

double func(bool x){
  if (x) {
    return 1.0;
  };
  return 2.0;
}

Are there performance reasons to favor one over the other?

The only thing I know is that the second faster to type.


I have been using g++, but would be interesting to learn what happens in others, if it is different.

Aucun commentaire:

Enregistrer un commentaire