Solved

use #define to name variable

Posted on 2002-05-29
4
227 Views
Last Modified: 2010-04-02
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
Comment
Question by:rs_1915
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 6

Accepted Solution

by:
thienpnguyen earned 50 total points
ID: 7042527
Yes, you can .

#define ADDLETTER( a ) td##a

int main()
{
    int ADDLETTER( bc );

   tdbc = 5;
   return 0;
}
0
 
LVL 86

Expert Comment

by:jkr
ID: 7042530
That's pretty easy:

#define ADDLETTER(a) td##a

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 7043454
Never mind what those guys say.  I suggest using the token-pasting operator, ##

-- Dan
0
 
LVL 86

Expert Comment

by:jkr
ID: 7043465
:o)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question