News for hackers. Stuff that matters.
Re:C++ Attribute: Likely, Unlikely by bee_rider on Sunday October 22, 2023 @03:03PM (#37978107)
> I could always write a conditional for the hot path up front, but code is for human readers, right?

Does C or C++ actually make any promises that it’ll assume the “true” branch of the conditional will be taken? I always assumed that the compiler could make whatever weird decision it wants for that sort of thing.

TBH I’d probably just write normal stuff as a function, and then call that function directly in cases where performance is really crucial, if it can be done safely… if such a case exists…

Re:C++ Attribute: Likely, Unlikely by twoodfin on Sunday October 22, 2023 @03:36PM (#37978375)
No. The traditional compiler heuristic is to assume backwards branches are taken (loops) and forward branches are not.