Hacker News new | ask | show | jobs
by bee_rider 976 days ago
> 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…

1 comments

No. The traditional compiler heuristic is to assume backwards branches are taken (loops) and forward branches are not.