1.
do{ /
code... ; /
code...; /
}while(0)
Why do we use "do while(0)" : This macro define can check if the defined symbal are excueted as a whole. here is an example.
if we define BST_DEBUG(fmt...)
#define BST_DEBUG(fmt...) printf("BST USI Debug %s /n", ##fmt); /
printf("File: %s, Line:%d /n", __FILE__, __LINE__)
instead of
#define BST_DEBUG(fmt...) do{ /
printf("BST USI Debug %s /n", ##fmt); /
printf("File: %s, Line:%d /n", __FILE__, __LINE__); /
}while(0)
. We will confrant with the problem if use it like this
if(a>0)
BST_DEBUG("Only one line output.../n");
So we can find that the latter define can output all string correctly.
-------------------------------------------------------------------------------------
2.
typedef struct mytype
{
int type;
int len;
int array[0];
}
-----------------------------------------
3
本文详细解析了do-while(0)宏定义的使用场景及其与普通do-while循环的区别,通过实例展示了其在调试和输出信息方面的独特优势。此外,文章还探讨了typedef结构的定义方式,并提供了有关类型定义和初始化的实用技巧。
1万+

被折叠的 条评论
为什么被折叠?



