I know that defines in the beginning of a C++ file are Preprocessor directives so “the preprocessor is executed before the actual compilation of code begins, therefore the preprocessor digests all these directives before any code is generated by the statements [1]”.
Now what if I have this simple example:
#define PRINT(function) printFnctionName(#function)
void printFnctionName(string name)
{
cout << name;
}
void test(){};
int main(int argc, char *argv[])
{
PRINT(test);
}
So now my question is really how does the precompiler know what function will be passed in? and how is the pre-compilation/linking/compilation really happening?
Also, the reason I am using define and not a regular function, it is because I wasn’t able to find a way to replicate this functionality `#function to retrieve the name of a function
Preprocessor doesn’t know about anything. It simply replaces the text with the defined value and stringifies the value you passed in.
So the compiler sees it: