for(x;x<crap;x++)
{
macro(x,y);开发者_如何学运维
}
How is this handled by preprocessor? Is this loop unrolled or something else?
The macro is expanded before the code is compiled - it doesn't matter whether it's in a loop or anywhere else.
#define macro(x, y) doSomething(x, y)
for(x;x<crap;x++){
macro(x,y);
}
will expand to:
for(x;x<crap;x++){
doSomething(x,y);
}
The context surrounding macro(x,y)
has no effect on how the preprocessor expands it.
(The preprocessor doesn't even know what programming language you're using - it could be C, Python, Brainfuck or a letter to your bank manager and it would expand macros just the same way.)
#define
macros can be thought of as a search and replace before compilation action happens. This means whatever your macro equates to will be directly substituded in its reference inside your code. No, the loop is no unrolled.
精彩评论