Solved

How do I write the Windows TEXT macro on linux?

Posted on 2010-11-27
5
846 Views
Last Modified: 2012-05-10
I am in the process of converting some c++ code from Windows to C++. I have a bunch of TEXT macros. TEXT("MyString") which makes L"MyString" or "MyString depending on some condition.

Ideally, on linux, I would simply like to define a macro that does the above. Something like:

#ifdef USE_WIDE_CHAR
#  define TEXT(x) L#x
#else
# define TEXT(x) x
#endif

But, the above does not seem to compile. Anyone know how to do this?

Thanks!
0
Comment
Question by:rjsurati
[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
5 Comments
 
LVL 86

Expert Comment

by:jkr
ID: 34222369
The same should work un Linux - see http://kfsone.wordpress.com/2008/08/26/unicode-literals-and-gcc/ ("Unicode literals and GCC"). What errors are you getting?
0
 
LVL 9

Expert Comment

by:Subrat (C++ windows/Linux)
ID: 34222733
If you want to use wide char, then define USE_WIDE_CHAR.
The file inwhich you need it, just define.better if defining inside a common file( which you need more frequently)

#define USE_WIDE_CHAR

Not worked on linux, but hope unicode and ascii concept is same irrespective of platform.
0
 
LVL 9

Expert Comment

by:masheik
ID: 34224055
You were not showing us the errors.I dont know how your project files were organized.    Say your project has 5 source files and 6 header files and I assume you were including one common header included to all other header files or to all the source files or to where it was required to make all the the declaration available to the source files , then in that header file use  #define USE_WIDE_CHAR                           and conditional includes  
0
 
LVL 11

Accepted Solution

by:
DeepuAbrahamK earned 500 total points
ID: 34228398
For ASCII, a LPTSTR is a char*.
For Unicode it becomes a wchar_t*.
Try these:
#ifdef USE_WIDE_CHAR
#define TEXT(x) L ##x
#else
#define TEXT(x) x

0
 

Author Comment

by:rjsurati
ID: 34294977
Sorry guys, this one ended up being my fault. I had

#define TEXT(x) L #x
does not work

#define TEXT(x) L ##x
does.

In my code, I accidentally added a ';' which is why I was so confused.

0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

Using 'screen' for session sharing, The Simple Edition Step 1: user starts session with command: screen Step 2: other user (logged in with same user account) connects with command: screen -x Done. Both users are connected to the same CLI sessio…
Fine Tune your automatic Updates for Ubuntu / Debian
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

688 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