On 8/1/2014 4:12 PM, Jonathan M Davis wrote:
True, but as long as the runtime cost isn't too great for your debug builds, having assertions for whatever conditions you think your code relies on and would ideally be checked is quite beneficial. Any optimizations by the compiler would then be a bonus, but the fact that they exist does offset the costs to debug builds somewhat (depending on what you're doing) by improving the release builds. I would think that any attempt to specifically craft assertions to aid the optimizer would be something that should generally be left to the cases where you really care about getting extra speed out of your program and are doing micro-optimizations based on profiling and the generated assembly and whatnot.
The optimizations thus enabled would be the same as in, say, an if body: if (expr) { ... take advantage of expr being true ... } and optimizers already do that to an increasing extent.