Solved

How do I write the Windows TEXT macro on linux?

Posted on 2010-11-27
5
785 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 8

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

When writing generic code, using template meta-programming techniques, it is sometimes useful to know if a type is convertible to another type. A good example of when this might be is if you are writing diagnostic instrumentation for code to generat…
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 video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

758 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

17 Experts available now in Live!

Get 1:1 Help Now