News for hackers. Stuff that matters.
Re:C++ Attribute: Likely, Unlikely by vore on Sunday October 22, 2023 @02:34PM (#37977879)
I'm so confused by this. How would you avoid doing these checks? Aren't they invariants for your function?
Re:C++ Attribute: Likely, Unlikely by bee_rider on Sunday October 22, 2023 @02:58PM (#37978057)
I don’t think they suggested avoiding the checks, unless I’ve missed something?
Re:C++ Attribute: Likely, Unlikely by vore on Sunday October 22, 2023 @03:22PM (#37978259)
The part that's confusing me is the part about avoiding clutter – if you have to do all the checks anyway, what clutter are you avoiding by changing the order of them?
Re:C++ Attribute: Likely, Unlikely by bee_rider on Sunday October 22, 2023 @03:30PM (#37978328)
I believe the likelihood annotations are the things they are talking about, for cluttering the code. Not the argument checks.
Re:C++ Attribute: Likely, Unlikely by gumby on Sunday October 22, 2023 @06:00PM (#37979479)
That conditional would be checked, then if it failed, checked again after the normal case has run, in order to choose the arm to follow.

Not a huge deal execution-time-wise, but from a reader’s PoV, the way I write it says, “ok, the special cases don’t apply to the body so I don’t have to worry that the index will be out of range (or whatever) and can just focus on the logic”.

Re:C++ Attribute: Likely, Unlikely by actionfromafar on Sunday October 22, 2023 @03:11PM (#37978170)
Maybe the implied question is that, the compiler can optimise the checks to the occur in whatever order it wants.