Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Macro, make wide string literal

Reply
Thread Tools

Macro, make wide string literal

 
 
Jim King
Guest
Posts: n/a
 
      04-22-2010
Given a macro which is a string literal. It cannot be changed since it
comes from some library.
#define ID_VERSION_STRING "5.3.3.98" // this macro cannot be
changed

I want a macro which is expanded as the wide character counterpart of
the string above.
#define IDW_VERSION_STRING ...ID_VERSION_STRING...
// make IDW_VERSION_STRING L"5.3.3.98"

Note: if ID_VERSION_STRING changes, I hope that IDW_VERSION_STRING
changes correspondingly.

How the definition of macro IDW_VERSION_STRING looks like?

Thanks.
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      04-22-2010
[Please do not mail me a copy of your followup]

Jim King <(E-Mail Removed)> spake the secret code
<(E-Mail Removed)> thusly:

>Given a macro which is a string literal. It cannot be changed since it
>comes from some library.
>#define ID_VERSION_STRING "5.3.3.98" // this macro cannot be
>changed
>
>I want a macro which is expanded as the wide character counterpart of
>the string above.
>#define IDW_VERSION_STRING ...ID_VERSION_STRING...
>// make IDW_VERSION_STRING L"5.3.3.98"
>
>Note: if ID_VERSION_STRING changes, I hope that IDW_VERSION_STRING
>changes correspondingly.
>
>How the definition of macro IDW_VERSION_STRING looks like?


If you're programming for the Windows API, include <tchar.h> and write
_T(ID_VERSION_STRING) when you want a wide or narrow string literal
depending on whether you compile ANSI or UNICODE.
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
 
Reply With Quote
 
 
 
 
Jim King
Guest
Posts: n/a
 
      04-22-2010
Hi Richard,

_T works. Thank you very much.

This can not work.
#define IDW_VERSION_STRING L ## ID_VERSION_STRING

error message from VS:
error C2065: 'LID_VERSION_STRING' : undeclared identifier

The point, WHY?
 
Reply With Quote
 
Jim King
Guest
Posts: n/a
 
      04-22-2010
On Apr 22, 9:15*pm, Victor Bazarov <(E-Mail Removed)> wrote:
> Jim King wrote:
> > Hi Richard,

>
> > _T works. Thank you very much.

>
> > This can not work.
> > #define IDW_VERSION_STRING L ## ID_VERSION_STRING

>
> > error message from VS:
> > error C2065: 'LID_VERSION_STRING' : undeclared identifier

>
> > The point, WHY?

>
> The problem is that the macro 'ID_VERSION_STRING' isn't expanded when
> 'IDW_VERSION_STRING' is substituted. *It's an old idiosyncrasy of the C
> preprocessor. *More preprocessor tricks are required. *Just use _T.
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


We are programming both on Windows and Mac OS.

I mimic _T macro on g++/Ubuntu. It works well.

#define __t(x) L ## x
#define _t(x) __t(x)

Interestingly, the __t must be defined before _t.

I'm very interested in these preprocessor tricks. Where can I find
them?

Thanks,
Jim
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-22-2010
On Apr 22, 6:39*am, Jim King <(E-Mail Removed)> wrote:
> On Apr 22, 9:15*pm, Victor Bazarov <(E-Mail Removed)> wrote:
>
>
>
> > Jim King wrote:
> > > Hi Richard,

>
> > > _T works. Thank you very much.

>
> > > This can not work.
> > > #define IDW_VERSION_STRING L ## ID_VERSION_STRING

>
> > > error message from VS:
> > > error C2065: 'LID_VERSION_STRING' : undeclared identifier

>
> > > The point, WHY?

>
> > The problem is that the macro 'ID_VERSION_STRING' isn't expanded when
> > 'IDW_VERSION_STRING' is substituted. *It's an old idiosyncrasy of the C
> > preprocessor. *More preprocessor tricks are required. *Just use _T.

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

>
> We are programming both on Windows and Mac OS.
>
> I mimic _T macro on g++/Ubuntu. It works well.
>
> #define __t(x) L ## x
> #define _t(x) __t(x)
>


Don't use __t. Any identifier with a double underscore is
reserved to the implementation; you may not declare it for
your own purposes.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      04-22-2010
[Please do not mail me a copy of your followup]

red floyd <(E-Mail Removed)> spake the secret code
<(E-Mail Removed)> thusly:

>Don't use __t. Any identifier with a double underscore is
>reserved to the implementation; you may not declare it for
>your own purposes.


And if I recall correctly, any identifier beginning with an underscore
followed by a capital letter is also reserved.

Its easiest to just avoid creating your own identifiers (macros,
variables, members, functions, namespaces, etc.) that start with an
underscore. Include guards are the most frequent violators of that
recommendation (__INCLUDED_HEADER_H__).
--
"The Direct3D Graphics Pipeline" -- DirectX 9 draft available for download
<http://legalizeadulthood.wordpress.com/the-direct3d-graphics-pipeline/>

Legalize Adulthood! <http://legalizeadulthood.wordpress.com>
 
Reply With Quote
 
red floyd
Guest
Posts: n/a
 
      04-22-2010
On Apr 22, 11:43*am, Pete Becker <(E-Mail Removed)> wrote:
> Richard wrote:
> > [Please do not mail me a copy of your followup]

>
> > red floyd <(E-Mail Removed)> spake the secret code
> > <(E-Mail Removed)> thusly:

>
> >> Don't use __t. *Any identifier with a double underscore is
> >> reserved to the implementation; you may not declare it for
> >> your own purposes.

>
> > And if I recall correctly, any identifier beginning with an underscore
> > followed by a capital letter is also reserved.

>
> And while we're at it, any identifier with two consecutive underscores
> is reserved. The example of __t is just a special (and quite common)
> case of this broader rule.
>


Uh, Pete? That's what I said.


 
Reply With Quote
 
Jim King
Guest
Posts: n/a
 
      04-23-2010
Hi everyone,

Thank you for your excellent analysis and advices. I learned so much.

Regards,
Jim King
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: DSLR lenses not good wide open at wide angle? Dauphin de Viennois Digital Photography 2 07-16-2008 12:29 PM
Wide Screen not wide enough? michelebargeman@yahoo.com DVD Video 31 04-27-2006 08:50 PM
Not many "wide-angle" compacts but, heck, many are wide-angle anyway! JeffOYB@hotmail.com Digital Photography 10 01-09-2006 08:30 AM
What's wrong with rpc-literal? Why use doc-literal? Anonieko Ramos ASP .Net Web Services 0 09-27-2004 09:06 AM
char 8bit wide or 7bit wide in c++? Web Developer C++ 2 07-31-2003 08:09 AM



Advertisments