while(0),, array[0]

来源:互联网 发布:python 中文版 pdf 编辑:程序博客网 时间:2024/04/29 19:10

 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

 

 

 

 

原创粉丝点击