jrheisey
asked on
GCC C++: Defining unicode string const in macro
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(CO NFIG_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'
#define DEFINE_XML_TOKEN_STRING(n,
DEFINE_XML_TOKEN_STRING(CO
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'
I would try compiling with compiler flag -std=c++11. Will try it when I can.
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
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
This macro works for g++
#define DEFINE_XML_TOKEN_STRING(n, s) const char n##a[] = #s; const wchar_t n##w[] = L###s;
You will have to test whether Visual Studio accepts it
ASKER
Then the pre-processor is adding the space. It is not in the macro definition.
ASKER
I filed a gcc bug
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60492
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60492
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.
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.