do{}while(0);
来源:互联网 发布:网络对实体店的冲击 编辑:程序博客网 时间:2024/05/16 17:38
第一次在 redis 的 dict 源码中看到这种用法。
1,用在宏中,come from stackoverflow
It's the only construct in C that you can use to #define
a multistatement operation, put a semicolon after, and still use within anif
statement. An example might help:
#define FOO(x) foo(x); bar(x)if (condition) FOO(x);else // syntax error here ...;
Even using braces doesn't help:
#define FOO(x) { foo(x); bar(x); }
Using this in an if
statement would require that you omit the semicolon, which is counterintuitive:
if (condition) FOO(x)else ...
If you define FOO like this:
#define FOO(x) do { foo(x); bar(x); } while (0)
then the following is syntactically correct:
if (condition) FOO(x);else ....
2,
用来做错误检查
It is a way to simplify error checking and avoid deep nested if's. For example:
do { // do something if (error) { break; } // do something else if (error) { break; } // etc..} while (0);
0 0
- do...while(0)
- do{}while(0)
- [转载]Do{}While(0)
- do {} while (0) 用法
- do-----while(0)
- do...while(0)
- do{}while(0)妙用
- do while(0) 用法
- do {} while (0)
- do..while(0)使用
- do{ ... } while(0)
- do-while(0)妙用
- do...while(0)用法
- do{...} while(0);
- do{ ... } while(0)
- do...while(0) 妙用
- 宏do{}while(0)
- do{}while(0)
- 随想
- Tomcat基本设置
- Hibernate中 一对一 唯一外键关联映射
- Ubuntu Linux, 不要弄什么 wine,龙井 或者什么等 QQ 了。
- 白话windows内核对象共享之继承
- do{}while(0);
- UVA 112(二叉树、DFS)
- KVO/KVC
- 现今中国大学生就业现状
- 李克强:继续稳健货币政策 适时适度预调微调
- flex swf载入
- 动态规划——数塔问题
- Linux下递归创建目录
- POJ 1151 - Atlantis 线段树+扫描线..