Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How do I write the Windows TEXT macro on linux?

Posted on 2010-11-27
5
Medium Priority
?
917 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
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:
Deepu Abraham earned 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Little introduction about CP: CP is a command on linux that use to copy files and folder from one location to another location. Example usage of CP as follow: cp /myfoder /pathto/destination/folder/ cp abc.tar.gz /pathto/destination/folder/ab…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
Suggested Courses
Course of the Month11 days, 10 hours left to enroll

916 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