I want to create a string based on the value passed as argument to the MACRO FUNCTION. Something Like:
#define ABC(x,y) return "anystr_x_y.tar.bz2"
main()
{
a = ABC(2,3);
}
So Finally, It should return "anystr_2_3.tar.bz2"
I was wondering how to create that string with the value passed as argument to MACRO fnc.
Any help ! thanks !
Define your macro like this, using the "stringize operator":
#define ABC(x,y) "anystr_" #x "_" #y ".tar.bz2"
Macros don't return stuff, since they are not functions. They are merely token replacement functionality. What you actually want is a though one, and in your place I would do it with a function instead. However, a solution could look like:
#define ABC(x,y) "anystr_" #x "_" #y ".tar.bz2"
This takes leverage from the fact that string literals are collapsed togheter, so "Hello " "World!"
is interpreted as "Hello World!"
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With