Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
可能重复: C/C++ 宏中的 Do-While 和 if-else 语句
我有以下宏:
#define FREE1(x) do { free(x); x = NULL; } while (0) #define FREE2(x) free(x); x = NULL
这些宏有什么区别?
自己解决这个问题可能会更令人满意。
暗示:
if(y) FREE2(x);
考虑以下示例
if (some_test) FREE2(x);
扩展到
if (some_test) free(x); x = NULL; // happens regardless of value of some_test