Solved

use #define to name variable

Posted on 2002-05-29
4
234 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
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.

728 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