This looks very hypothetical. Since you appear to be expecting the compiler to treat both k and -k equally as constants, it's unlikely to make a difference. I can imagine related situations where the negation might be an additional operation, or where it might pay off by enabling commutation optimizations.
-=k or +=-k ?
如需更全面地了解编译器优化,请参阅优化注意事项.





-=k or +=-k ?
Hi there, sorry if this question is too easy :)
Has the addition of a negative constant better or same performance than the substraction of the positive constant?
In other words, does the ALU need to perform the ~2 or it resolves it by truth-table, so exactly the same clocktics are required?
Thanks!
Daniel.