How can I declare variables via macros?

As @Chris Lutz has rightly said that, there might be a better way to accomplish what you want. Consider asking what you want to achieve.

As @Chris Lutz has rightly said that, there might be a better way to accomplish what you want. Consider asking what you want to achieve. But if you are just curious, this is the way to do: #define var(z) int g_iLine##z##var = 0 #define decl(x) var(x) #define MY_LINE_VARIABLE decl(__LINE__) MY_LINE_VARIABLE; MY_LINE_VARIABLE.

Thank you for your help!. I'm pretty newbie about macros. So your commnet will be helpful to me.

– Darpangs Aug 5 '11 at 5:48.

From this link : After the preprocessor expands a macro name, the macro's definition body is appended to the front of the remaining input, and the check for macro calls continues. Therefore, the macro body can contain calls to other macros. So in your case : MY_VARIABLE_LINE is converted to int g_iLine__LINE__Var;.

But now __LINE__ is not a valid token anymore and is not treated as a predefined macro. Aditya's code works like this: MY_VARIABLE_LINE is converted to decl(__LINE__) which is converted to var(123) which is converted to int giLine123var = 0. Edit: This is for GNU C.

Thank you for your explaining. – Darpangs Aug 5 '11 at 8:39.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions