Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Replace _T() macros

2 views
Skip to first unread message

John Doe

unread,
Oct 29, 2008, 12:25:27 PM10/29/08
to
Hi,

I would like to know if it would be possible to replace _T() macros used
on windows to delcare an ANSI string or a unicode one :

#ifdef UNICODE
#define __TEXT(quote) L##quote // r_winnt
#else
#define __TEXT(quote) ##quote
#endif

#define _T(x) __TEXT(x)

I was thinking of something like

_Text<char>("some text") that would return "some text"
and
_Text<wchar_t>("some text") that would return L"some text"

What is possible to do ?


Victor Bazarov

unread,
Oct 29, 2008, 1:03:57 PM10/29/08
to

First off, the name '_Text' is reserved by the implementation. Do *not*
under any circumstances name your variables/functions starting with an
underscore and a capital letter. That aside...

You cannot expect to define some mechanism that would somehow tweak your
source code and hope for it *not* to be a macro. That's the point. It
has to be a macro to squeeze the 'L' in front of the literal before the
compiler gets its hands on the code.

What is it you're trying to accomplish?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask

James Kanze

unread,
Oct 30, 2008, 5:51:25 AM10/30/08
to

> #define _T(x) __TEXT(x)

The obvious first answer is that the above is impossible, since
the arguments to a macro have to be in the parentheses.

The obvious second answer is that it is trivial to write a small
preprocessor which does this; probably around a hundred lines of
code, in all (using flex and a simple state machine).

A less obvious third answer is that it doesn't buy you anything.
The way you process wide characters is different than what you
do with narrow characters; just changing char to wchar_t and
"..." to L"..." won't produce anything usable.

--
James Kanze (GABI Software) email:james...@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

0 new messages