Solved

use #define to name variable

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Prototype for MessageDlg in Embacadero XE 2 2 35
C++ question 3 62
Which Linux flavors will this run on? 6 76
FMX TCameraComponent Problem 2 52
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
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…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

910 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now