3 ms·
I assume the compiler can easily optimize something like that similar to constant folding. Isn't that the case?
by rowanG077 8y ago
I assume the compiler can easily optimize something like that similar to constant folding. Isn't that the case?
- jerf 8y agoIn most cases I'd expect so. The rare cases I was thinking of was on the order of "I'm on an embedded system using a crappy compiler and I can't change it and I literally can't afford extra bytes for boolean values the compiler won't optimize away", and on the other end, "I'm in the cloud and my code has confused the optimizer and I have to code this inner loop incredibly carefully because it's going to be called several billion times per second". Maybe the odd other corner case here or there. There shouldn't be much in-between in 2019 where writing the clauses out this way will have a materially negative impact on one's code, and it should have a generally very positive one.
- p2t2p 8y agoIn this case I'd probably write an inline function which would accept all those booleans and then return (x && y) || (a && b) && !(c != d) //pseudo example of complex condition Or write a bunch of macros given that if you're on embedded 99.999% probability you're writing C.