可能重複:
Why are there sometimes meaningless do/while and if/else statements in C/C++ macros?爲什麼要用循環,而不是在宏塊用C
您好,在很多C宏程序員使用特殊的一環,例如:
#define do_something(a) do { execute(a); count(a); } while(0)
因爲當你想在循環中做這個宏並且你不使用「{}」。 爲什麼他們不使用簡單的塊呢?我的意思是,不是
#define do_something(a) { execute(a); count(a); }
有非常相同的效果?
-1:什麼?這不是原因。 – 2011-05-22 16:54:22
這不是原因,但它是一個原因。 – Hogan 2011-05-22 17:05:05