Author Topic: Internalization, multi-line _T() and _() macros  (Read 13467 times)

Offline maxblagaj

  • Single posting newcomer
  • *
  • Posts: 8
Internalization, multi-line _T() and _() macros
« on: February 25, 2007, 07:57:03 pm »
Hi,

I have a generic question about multi-line _T() and _() macros.
So far I can see _T("abc") is converted to L"abc" which is ok for single line strings,
but if you have something like this:

_("first line"
"second line")

it gets converted to:

L"first line"
"second line"

which make my compiler bark about concatenation of incompatible strings.
The solution is easy -> I can just put the second line inside of another _T().


So the main question is if somebody sees any problems with this one?
I think there should be string extraction utility or something.


Regards,
Max.
Fair fight is the one you won.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 6434
    • My Best Post
Re: Internalization, multi-line _T() and _() macros
« Reply #1 on: February 25, 2007, 08:16:02 pm »
Are you sure that you had trouble with _T(), I have only had issues with _() with MSVC or gcc 3.3 I can NOT remember which one. Which compiler are you using?

Tim S
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 32 bit.
On Debian Stretch, compiling CB Trunk against wxWidgets 3.0.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline maxblagaj

  • Single posting newcomer
  • *
  • Posts: 8
Re: Internalization, multi-line _T() and _() macros
« Reply #2 on: February 25, 2007, 08:19:08 pm »

gdb_driver.cpp
d:\work\codeblocks\src\plugins\debuggergdb\gdb_commands.h(323) : error C2308: concatenating mismatched strings
        Concatenating wide "While setting up custom conditions for breakpoint %d (%s, line %d),
" with narrow "the debugger responded with the following error:
"
d:\work\codeblocks\src\plugins\debuggergdb\gdb_commands.h(323) : error C2308: concatenating mismatched strings
        Concatenating wide "While setting up custom conditions for breakpoint %d (%s, line %d),
" with narrow "
Error: %s
"
d:\work\codeblocks\src\plugins\debuggergdb\gdb_commands.h(323) : error C2308: concatenating mismatched strings
        Concatenating wide "While setting up custom conditions for breakpoint %d (%s, line %d),
" with narrow "Do you want to make this an un-conditional breakpoint?"
Fair fight is the one you won.

Offline maxblagaj

  • Single posting newcomer
  • *
  • Posts: 8
Re: Internalization, multi-line _T() and _() macros
« Reply #3 on: February 25, 2007, 08:21:43 pm »
I've got it to build with MSVC 8. I can provide patches & project files for that if somebody is interested.

At the moment I just going though all my changes and thinking what can be reused without problems.
Fair fight is the one you won.

Offline byo

  • Plugin developer
  • Lives here!
  • ****
  • Posts: 837
Re: Internalization, multi-line _T() and _() macros
« Reply #4 on: February 26, 2007, 12:52:27 am »
Solution is rather simple: When concatenating strings using _T() you
must put each string inside _T() macro:
Code: [Select]
_T("First ") _T("Second"),
when using _(), you must put all strings inside one macro:
Code: [Select]
_("First " "Second")
At least that would conform to C++ specification of concatenating strings ;)

Regards
  BYO

Offline maxblagaj

  • Single posting newcomer
  • *
  • Posts: 8
Re: Internalization, multi-line _T() and _() macros
« Reply #5 on: February 26, 2007, 10:31:10 am »
Solution is rather simple: When concatenating strings using _T() you
must put each string inside _T() macro:
Code: [Select]
_T("First ") _T("Second"),
when using _(), you must put all strings inside one macro:
Code: [Select]
_("First " "Second")

Thanks for the solution but my question was about something else -> I already solved that.

The solution is easy -> I can just put the second line inside of another _T().


The question was more about "the right way" and additional problems somebody can get with string extraction utility, for example.

At least that would conform to C++ specification of concatenating strings ;)

I also find it better this way. Should kind of positivly improve karma:)

Regards,
Max.
Fair fight is the one you won.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: Internalization, multi-line _T() and _() macros
« Reply #6 on: February 26, 2007, 11:04:55 am »
I can't reproduce the problem with gcc. Although gcc is not 100% standards-compliant in that it allows you to do a few illegal things, I like using it as my personal "correctness" test (which allows for an occasional false positive).
If gcc complains about something it is certainly wrong. If gcc does not bark, it is 80% certain standard. :)

I'm not sure why it works here, but my guess is the compiler concatenates the strings before evaluating macros?

Anyway, this is another good example how obnoxious, abusive, and misleading macros are.
Byo's example _("First " "Second") indeed resolves to wxGetTranslation(_T("First " "Second")) which resolves to wxGetTranslation(L"First " "Second")), respectively.
Also note that this only works at all because _T is defined earlier than _ (remember there is only a single preprocessor pass). In other words, the functionality depends on the order in which include files are read...
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."