|
-
October 30th, 2002, 11:46 AM
#1
I want to acheive this
I want to acheive the following
void ab()
{
}
#define X1 a
#define X2 b
#define X X1##X2
X(); // So I want this to be equivalent to calling ab()
any ideas how i can acheive that ?
-
October 30th, 2002, 12:29 PM
#2
Why not just call ab()?
Regards,
Paul McKenzie
-
October 30th, 2002, 02:41 PM
#3
// Helper macro _CONCAT:
// The following piece of macro magic joins the two
// arguments together, even when one of the arguments is
// itself a macro (see 16.3.1 in C++ standard). The key
// is that macro expansion of macro arguments does not
// occur in _CONCAT2 but does in _CONCAT1.
#define _CONCAT( _HEAD, _TAIL ) _CONCAT1( _HEAD, _TAIL )
#define _CONCAT1( _HEAD, _TAIL ) _CONCAT2( _HEAD, _TAIL )
#define _CONCAT2( _HEAD, _TAIL ) _HEAD##_TAIL
Now if you use the macro _CONCAT like this:
#define X1 a
#define X2 b
_CONCAT( X1, X2 )
you will get 'ab' after prefrocessing.
BTW: You can add /P option in Project Settings\C/C++\General\Project Options to get preprocessed output in MSVC Dev Studio.
-
October 30th, 2002, 03:10 PM
#4
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|