什么是“do {} while(0)”的重点是什么? [英] what's the point of "do {} while(0)"

查看:82
本文介绍了什么是“do {} while(0)”的重点是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在网络编程中学习选择。在Windows中遇到FD_SET的实现时我有一个问题(如下)。我的问题是为什么多余使用do-while?

感谢您的关注。

 #定义FD_SET(fd,set)do {\ 
u_int __i; \
for (__ i = 0 ; __ i<((fd_set FAR *)( set)) - > fd_count; __ i ++){\
if (((fd_set FAR *)(set)) - > fd_array [__i] ==(fd)){\
break ; \
} \
} \
if (__ i ==((fd_set FAR *)(set)) - > fd_count){\
if (((fd_set FAR *)(set)) - > fd_count< FD_SETSIZE){\
((fd_set FAR *)(set)) - > fd_array [__ i] =(fd); \
((fd_set FAR *)(set)) - > fd_count ++; \
} \
} \
} while 0

解决方案

这是胡说八道,我从来没用过它。



http://stackoverflow.com/questions/257418/do -while-0-what-it-good-for [ ^ ]



http://www.quora.com/What-is-the-purpose-of-using-do-while- 0-in-macros [ ^ ]



http://www.codeofhonor.com/blog/error-handling-using-forever-loop [ ^ ]



http://www.osronline.com/ showThread.CFM?link = 232772 [ ^

Hi,
I'm studying select in network programming. I have a question when encountering the implementation of FD_SET in Windows(as follow). My question is why redundantly use do-while ?
Thanks for your attention.

#define FD_SET (fd, set) do { \
    u_int __i; \
    for ( __i = 0; __i < ((fd_set FAR *)(set ))->fd_count; __i++) { \
        if (((fd_set FAR *)( set))->fd_array [__i] == ( fd)) { \
            break; \
        } \
    } \
    if ( __i == ((fd_set FAR *)( set))->fd_count ) { \
        if (((fd_set FAR *)( set))->fd_count < FD_SETSIZE) { \
            (( fd_set FAR *)(set))-> fd_array[__i ] = (fd); \
            (( fd_set FAR *)(set))-> fd_count++; \
        } \
    } \
} while(0)

解决方案

It's nonsense, I've never used it.

http://stackoverflow.com/questions/257418/do-while-0-what-is-it-good-for[^]

http://www.quora.com/What-is-the-purpose-of-using-do-while-0-in-macros[^]

http://www.codeofhonor.com/blog/error-handling-using-forever-loop[^]

http://www.osronline.com/showThread.CFM?link=232772[^]


这篇关于什么是“do {} while(0)”的重点是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆