What is double evaluation and why should it be avoided?
问题 I was reading that in C++ using macros like #define max(a,b) (a > b ? a : b) can result in a 'double evaluation'. Can someone give me an example of when a double evaluation occurs and why it's bad? P.S.: Surprisingly I couldn't find any detailed explanation when googling for it except for an example in Clojure (which I can't understand). 回答1: Imagine you wrote this: #define Max(a,b) (a < b ? b : a) int x(){ turnLeft(); return 0; } int y(){ turnRight(); return 1; } then called it like this: