Developer forums (C::B DEVELOPMENT STRICTLY!) > Contributions to C::B

Internalization, multi-line _T() and _() macros

<< < (2/2)

maxblagaj:

--- Quote from: byo 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: ---_T("First ") _T("Second")
--- End code ---
,
when using _(), you must put all strings inside one macro:

--- Code: ---_("First " "Second")
--- End code ---

--- End quote ---

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


--- Quote from: maxblagaj on February 25, 2007, 07:57:03 pm ---The solution is easy -> I can just put the second line inside of another _T().

--- End quote ---


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


--- Quote from: byo on February 26, 2007, 12:52:27 am ---At least that would conform to C++ specification of concatenating strings ;)

--- End quote ---

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

Regards,
Max.

thomas:
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...

Navigation

[0] Message Index

[*] Previous page

Go to full version