Jump to content
  • Advertisement
Sign in to follow this  
Rattrap

#define MACRO question

This topic is 4925 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Below are some snippets of some code I'm working on. I'm working on setting up a little platform independant architecture library. I'm having trouble with a #define constant being used within a #define macro.
//  This value will depend on the setup configuration.
//  While this could potentially be a const instead of define, right
//  now I want it purely in the preprocessor
#define	ARCHITECTURE_STRING	"X86_32"

//  The multibyte macro - converts strings to multibyte
//  There is also a version of TEXT(x) that is just x for non-multibyte
#define	TEXT(x)	L##x

//  Basically converts the string to the appripriate characters set
//  Be it multibyte or single byte, depending on how TEXT is defined
#define	ARCHITECTURE_NAME	TEXT( ARCHITECTURE_STRING )


What I get when I try to print is LARCHITECTURE_STRING being passed in place of ARCHTECITURE_NAME, when I'm hoping for the multibyte translation of ARCHITECTURE_STRING L"X86_32". Is there a way to get this to work, while leaving these all using #defines? I would also like to note, I am using Visual C++ 2005 Express beta.

Share this post


Link to post
Share on other sites
Advertisement
I've never been able to get a define with in a define to work. The #define see's teh '#' from the other #define and doesn't know what to do with it.

Hopefully some one here can show me how. I wanted to do it for vs.net #pragma's and gcc #warnings so I could create a cross platform compile time messaging library.

Good luck, let me know if you get a solution.

Cheers
Chris

Share this post


Link to post
Share on other sites
Quote:
Original post by Rattrap
What do you mean?
I mean like this:
//  This value will depend on the setup configuration.
// While this could potentially be a const instead of define, right
// now I want it purely in the preprocessor
#define ARCHITECTURE_STRING "X86_32"

// The multibyte macro - converts strings to multibyte
// There is also a version of TEXT(x) that is just x for non-multibyte
#define TEXT(x) L##x
#define INDIRECT_TEXT(x) TEXT( x )

// Basically converts the string to the appripriate characters set
// Be it multibyte or single byte, depending on how TEXT is defined
#define ARCHITECTURE_NAME INDIRECT_TEXT( ARCHITECTURE_STRING )

Share this post


Link to post
Share on other sites
boost has some macros defined that will do what you are looking for. IIRC you want to look at BOOST_PP_CAT

Share this post


Link to post
Share on other sites
Quote:
Original post by chollida1
doynax,
Have you tested your solution?? I"m not so sure that will work:)


His method works fine and is the standard solution to such problems...

Share this post


Link to post
Share on other sites
Really, well that's great!!!

Can you show me how to get this to work with BOOST_PP_CAT.

#ifdef _WIN32
#define message(x) #pragma message "hello"
#else
#define message(x) #warningmessage "hello"
#endif

I also tried putting '#' in my definitions and the BOOST_PP_CAT causes preprocessor to error, Since you say its possible, how do you get '#' in preprocessor macros?? I'd love this feature:)

Bye the way you usually seem like a nice guy/girl, what's up with the terse answer:)

Cheers
CHris

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!