What is mean of #name ?

Jan 20, 2017 at 7:29pm
I saw some codes using macro definition to define a function alais. But I don't understand why it put "#" before argument like this :


1
2
#define RegisterTcpFlow(name) \
    RegisterFlow(#name, &name::Construct, eTcp); \ 


What does #name mean ?

Thanks in advance.
Jan 20, 2017 at 8:30pm
It will give you the name as a string.

RegisterTcpFlow(hello) will expand to RegisterFlow("hello", &hello::Construct, eTcp);
Jan 20, 2017 at 10:04pm
Thank you for reply. So it means it will convert hello as a variable to a string which is the variable name. Correct ?
Jan 21, 2017 at 10:42am
You can pass almost anything as argument to a macro, not just variables.

1
2
3
4
5
6
7
8
#include <iostream>

#define STR(str) #str

int main()
{
	std::cout << STR(This will be turned into a string.\n\t123...);
}
This will be turned into a string.
	123...
Last edited on Jan 21, 2017 at 11:10am
Topic archived. No new replies allowed.