1

I see many examples using the unlikely macro (not the C++20 attribute) as if( unlikely( server == 0 ) ), but never combining them both as if( unlikely( server == 0 ) || unlikely( client == 0 ) ) or if( unlikely( server == 0 || client == 0 ) ).

Can I need to use two unlikely on two conditionals for the same if or the unlikely is interpreted correctly if used only once in the whole if condition as in if( unlikely( server == 0 || client == 0 ) )?

Other questions about unlikely:

  1. gcc likely unlikely macro usage
  2. efficient, extremely-unlikely conditionals?
  3. likely and unlikely macros
  4. likely/unlikely instead of if/else
Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
Evandro Coan
  • 8,560
  • 11
  • 83
  • 144
  • unlikely applies to the condition as a whole, thats why I dont really understand your worries. Why does it matter how to correctly place it on two parts of the conditions, when it only matters that its on that branch? – 463035818_is_not_an_ai Jan 12 '23 at 18:58
  • @463035818_is_not_a_number: Where does the documentation say `unlikely` applies to “the condition as a whole”? – Eric Postpischil Jan 12 '23 at 19:04
  • 3
    @463035818_is_not_a_number The `||` is short-circuiting, so there might be a "hidden" branch in it as well, that might be likely or unlikely. – Eugene Sh. Jan 12 '23 at 19:05
  • 1
    @EricPostpishil I think I confused it with the C++ likely/unlikely, which as I understand does apply to the branch taken. Anyhow, I was wrong. – 463035818_is_not_an_ai Jan 12 '23 at 19:10

0 Answers0