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

Issue with Macro __DATE__ and UNICODE

423 views
Skip to first unread message

Mosfet

unread,
Feb 19, 2008, 3:16:29 PM2/19/08
to
Hi,

I am trying to port a piece of code under windows mobile where UNICODE
is used natively.

One line is defined like this :

#ifdef _UNICODE
#define UL_TEXT(s) L##s
#else
#define UL_TEXT(s) (s)
#endif

const wchar_t* _Vendor = UL_TEXT("bla bla");
const wchar_t* _Version = UL_TEXT( "Library Utilities 1.10.24 " __DATE__);

When I compile I get :

concatenating wide "Library Utilities 1.10.24 " with narrow "Feb 19 2008"

it seems __DATE__ is not expanded inside UL_TEXT.

I also tried like this

const wchar_t* _Version = UL_TEXT( "Library Utilities 1.10.24 ")
UL_TEXT( __DATE__);

bit I get the following error :

error C2146: syntax error : missing ';' before identifier 'L__DATE__'

What should I do ?

Bogdan

unread,
Feb 19, 2008, 4:17:02 PM2/19/08
to
#ifdef _UNICODE

#define WIDEN2(x) L ## x

#define WIDEN(x) WIDEN2(x)

#else

#define WIDEN(x)

#endif

const wchar_t* pszDate = WIDEN(__DATE__);

This should work.

Bogdan

"Mosfet" <anon...@free.fr> wrote in message
news:47bb3891$0$17178$426a...@news.free.fr...

Bogdan

unread,
Feb 19, 2008, 4:29:26 PM2/19/08
to
For non-wide chars it shoud read #define WINDEN(x) (x). I missed (x) in my
original reply.
BTW, a simple _T(__DATE__) will also do the trick if you do not need to use
L"".

Bogdan

"Bogdan" <bog...@domain.com> wrote in message
news:u6vdKzz...@TK2MSFTNGP04.phx.gbl...

Joseph M. Newcomer

unread,
Feb 19, 2008, 4:35:33 PM2/19/08
to
Yes, this is expected behavior.

First, why are you defining a macro called UL_TEXT when _T() does exactly the same thing
without any effort on your part? Why are you not using tchar.h?

Why are you declaring variables of type wchar_t * when the expression to the right-hand
side might be non-Unicode? This is incorrect code if compiled ANSI, and therefore there
is no need for the macro at all:
LPCWSTR _Vendor = L"bla bla";
or
LPCTSTR _Vendor = _T("bla bla");

To handle __DATE__ you would do
LPCWSTR _Version = L"bla bla" WC(__DATE__);
where you define
#define _WC(s) L##s
#define WC(s) _WC(s)

You need the second level of macro expansion to get the result you want. Of course, _T()
already does this, so not using it is surprising. If you needed to imitate it, then the
best strategy would be to at least use it as a model.

To be Unicode-aware, the code should be

LPCTSTR _Vendor = _T("bla bla");
LPCTSTR _Version = _T("Library Utilities 1.10.24 ") _T(__DATE__);
joe

Joseph M. Newcomer [MVP]
email: newc...@flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm

0 new messages