一个比较有意思的宏

    技术2022-05-20  42

    #define BUILD_BUG_ON_ZERO(e) (sizeof(struct { int:-!!(e); }))

    这个宏为编译时判断e是否为0

    假如e等于非0值,则!(e)0,则!!(e)1。再struct{int:-1}则会编译出错。

    假如e等于0,则!(e)1,则!!(e)0。再struct{int:-0},实际等价于struct{int:0}则编译通过。

     


    最新回复(0)