Solved

How do I write the Windows TEXT macro on linux?

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Can't ping New Linux Servers 40 65
fedora linux on laptop - setup sendmail - or some kind of email 5 43
maybe no no httpd.conf 6 46
bash file 10 36
Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
SSH (Secure Shell) - Tips and Tricks As you all know SSH(Secure Shell) is a network protocol, which we use to access/transfer files securely between two networked devices. SSH was actually designed as a replacement for insecure protocols that sen…
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

776 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