• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 249
  • Last Modified:

use #define to name variable

I am trying to name the variable using define
example #define ADDLETTER(a) will add letters 'td' to a, and declare this variable with that name.
So, If i declare int ADDLETTER( a); compiler should compile it as int tda;
second example
int ADDLETTER( bc );
the compiler will compile as
int tdbc;
Is this even possible to do?
0
rs_1915
Asked:
rs_1915
  • 2
1 Solution
 
thienpnguyenCommented:
Yes, you can .

#define ADDLETTER( a ) td##a

int main()
{
    int ADDLETTER( bc );

   tdbc = 5;
   return 0;
}
0
 
jkrCommented:
That's pretty easy:

#define ADDLETTER(a) td##a

0
 
DanRollinsCommented:
Never mind what those guys say.  I suggest using the token-pasting operator, ##

-- Dan
0
 
jkrCommented:
:o)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now