3 ms·
> 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 assum
by bee_rider 3y 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…
- twoodfin 3y agoNo. The traditional compiler heuristic is to assume backwards branches are taken (loops) and forward branches are not.
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]
- deleted 3y ago[deleted]