Day11-预处理,宏定义,条件编译,文件包含,头文件,gcc编译流程
预处理
...
...
...
...
...
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
如果x的值是个表达式5 3,而代码又写成这样:SUM SUM
,宏展开之后将变成:(5 3) + (5 3) (5 3) + (5 * 3)。这显然也是不对的,所以最外层的括号也别省略。
...
...
...
...
...
预定义好的宏
...
...
...
...
...
...
...
...
...
...
...
...
...
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
“#”运算符
...
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
#define PRINT(x) printf(#x)
#define DEBUG(x) printf(“the num “ #x “is :%d\n”, x);
则:
PRINT(abcdef) ==> printf(“abcdef”);
PRINT(12345) ==> printf(“12345”)
DEBUG(5) ==> printf(“the num 5 is :%d\n”, 5);
“##”运算符
##运算符可在宏定义中进行字符串的连接,比如:
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
language | c++ |
---|---|
theme | Confluence |
linenumbers | true |
collapse | false |
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
用宏可以实现的一些骚操作,比如:
代码块 | ||||||||
---|---|---|---|---|---|---|---|---|
| ||||||||
#define HI_APPCOMM_LOG_AND_RETURN_IF_FAIL(ret, errcode, errstring) \
do { \
if ((ret) != HI_SUCCESS) { \
MLOGE("[%s] failed[0x%08X]\n", (errstring), (ret)); \
return (errcode); \
} \
} while (0)
|
...