Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

GCC C++: Defining unicode string const in macro

Posted on 2014-03-09
9
Medium Priority
?
1,115 Views
Last Modified: 2014-03-10
This macro is intended to define a string as both ASICII and unicode.

#define DEFINE_XML_TOKEN_STRING(n, s) const char n##a[] = #s; const wchar_t n##w[] = L#s;

DEFINE_XML_TOKEN_STRING(CONFIG_ELM, config)

Show result in this code:

const char CONFIG_ELMa[] = "config"; const wchar CONFIG_ELMw[] = L"config";

Works with fine Visual Studio. The preprocessor in GCC seems to have a problem reporting error:
error: 'L' was not declared in this scope
note: in expansion of macro 'DEFINE_XML_TOKEN_STRING'
0
Comment
Question by:jrheisey
[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
  • 6
  • 2
9 Comments
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39916651
I would try compiling with compiler flag -std=c++11. Will try it when I can.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39916673
It works for me without any special flags. I have gcc 4.8.2 - what do you have?
Also I had to use wchar_t rather than wchar
14:53:04$ cat t.cpp
using namespace std;
int main (int argc, char **argv)
{
  const char CONFIG_ELMa[] = "config"; const wchar_t CONFIG_ELMw[] = L"config";
  return 0;
}                                  /* int main (int argc, char **argv) */
15:02:10$ cat Makefile 
t: t.cpp
        g++ $^ -o $@
15:02:14$ make
g++ t.cpp -o t

Open in new window

0
 
LVL 35

Accepted Solution

by:
Duncan Roe earned 900 total points
ID: 39916680
Now I see your problem.  Your macro expands to
const char CONFIG_ELMa[] = "config"; const wchar_t CONFIG_ELMw[] = L "config";

Open in new window

Note the space after "L".
0
Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39916685
This macro works for g++
#define DEFINE_XML_TOKEN_STRING(n, s) const char n##a[] = #s; const wchar_t n##w[] = L###s;

Open in new window

You will have to test whether Visual Studio accepts it
0
 
LVL 1

Author Comment

by:jrheisey
ID: 39917929
Then the pre-processor is adding the space. It is not in the macro definition.
0
 
LVL 1

Author Comment

by:jrheisey
ID: 39918756
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39918785
Fine. But you now have a solution. Does Visual Studio accept the amended macro? If not, you will have to conditionally define the macro according to platform.
0
 
LVL 35

Expert Comment

by:Duncan Roe
ID: 39919489
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60492

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You could most likely also use L"" #s too due to string concatenating rules.

Open in new window

0

Featured Post

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

604 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