usage of “\” in C?

拈花ヽ惹草 提交于 2019-12-02 15:23:37

问题


I was looking over this code, but i was unable to figure out why the usage of "\" after the && operator?

if ((*(u32*)(kaddr + 0x64) == *(u32*)(kaddr + 0x78)) && \
    (*(u32*)(kaddr + 0x68) == *(u32*)(kaddr + 0x88)))

回答1:


The \ right before the end of the line glues the following line to the current. Since C normally ignores whitespace, this is mostly useful when declaring macros.




回答2:


The backslash is not needed, unless this is part of a #define.

From the C specification §5.1.1.2

Each instance of a backslash character (\) immediately followed by a new-line character is deleted, splicing physical source lines to form logical source lines.

But it's not needed since the C language doesn't require that an if statement be placed on a single line.




回答3:


Among its uses are Macro definitions, basically it tells the compiler not to stop at the end of the line but rater to continue. example:

#define ASSERT_NULL(value)      \
    do {                        \
        if((value) == NULL) {   \
            return true;        \
        }                       \
    } while(NULL)

Now, if you won't put \, you won't get the functionality you're looking for.



来源:https://stackoverflow.com/questions/32021878/usage-of-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!