Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Macro tricks

Reply
Thread Tools

Macro tricks

 
 
Karim
Guest
Posts: n/a
 
      01-08-2007
Hi,

I have alot of constants that I need in regular char and in wchar_t
form

so instead of writing

#define const1 "value1"
#define const1wide L"value1"

I want to make some other macro that would save time from duplicate
definitions.

so I was thinking of

#define const1 "value1"

and another macro
#define WIDE(str) (##L str)

this almost works except for that the L has to stick to the "

I tried alot of other forms but I still can`t reach the result I want.

I don`t know if this is doable..

Any ideas?

 
Reply With Quote
 
 
 
 
Ondra Holub
Guest
Posts: n/a
 
      01-08-2007

Karim napsal:
> Hi,
>
> I have alot of constants that I need in regular char and in wchar_t
> form
>
> so instead of writing
>
> #define const1 "value1"
> #define const1wide L"value1"
>
> I want to make some other macro that would save time from duplicate
> definitions.
>
> so I was thinking of
>
> #define const1 "value1"
>
> and another macro
> #define WIDE(str) (##L str)
>
> this almost works except for that the L has to stick to the "
>
> I tried alot of other forms but I still can`t reach the result I want.
>
> I don`t know if this is doable..
>
> Any ideas?


#define WIDE(str) (L##str)

 
Reply With Quote
 
 
 
 
=?ISO-8859-1?Q?Erik_Wikstr=F6m?=
Guest
Posts: n/a
 
      01-08-2007
On 2007-01-08 22:31, Karim wrote:
> Hi,
>
> I have alot of constants that I need in regular char and in wchar_t
> form
>
> so instead of writing
>
> #define const1 "value1"
> #define const1wide L"value1"
>
> I want to make some other macro that would save time from duplicate
> definitions.
>
> so I was thinking of
>
> #define const1 "value1"
>
> and another macro
> #define WIDE(str) (##L str)


I have not tested this but I found it in an example in the MSDN-
documentation and it seems to be what you are looking for:

#define WIDEN2(x) L ## x
#define WIDEN(x) WIDEN2(x)

and the usage would be

#define const1 "value"
WIDEN(value)

Don't ask me how it works, I think I know but as I said, I have not
tested it.

--
Erik Wikström
 
Reply With Quote
 
Karim
Guest
Posts: n/a
 
      01-08-2007
This doesn`t work.

Cause say you have the two lines.
#define const1 "value1"
#define WIDE(str) (L##str)

so in the code when you would type for ex. : someFunc(WIDE(const1));

the compiler would paste in LSTR which results in compile error.

Thanks.

Ondra Holub wrote:
> Karim napsal:
> > Hi,
> >
> > I have alot of constants that I need in regular char and in wchar_t
> > form
> >
> > so instead of writing
> >
> > #define const1 "value1"
> > #define const1wide L"value1"
> >
> > I want to make some other macro that would save time from duplicate
> > definitions.
> >
> > so I was thinking of
> >
> > #define const1 "value1"
> >
> > and another macro
> > #define WIDE(str) (##L str)
> >
> > this almost works except for that the L has to stick to the "
> >
> > I tried alot of other forms but I still can`t reach the result I want.
> >
> > I don`t know if this is doable..
> >
> > Any ideas?

>
> #define WIDE(str) (L##str)


 
Reply With Quote
 
Victor Bazarov
Guest
Posts: n/a
 
      01-08-2007
Erik Wikström wrote:
> On 2007-01-08 22:31, Karim wrote:
>> Hi,
>>
>> I have alot of constants that I need in regular char and in wchar_t
>> form
>>
>> so instead of writing
>>
>> #define const1 "value1"
>> #define const1wide L"value1"
>>
>> I want to make some other macro that would save time from duplicate
>> definitions.
>>
>> so I was thinking of
>>
>> #define const1 "value1"
>>
>> and another macro
>> #define WIDE(str) (##L str)

>
> I have not tested this but I found it in an example in the MSDN-
> documentation and it seems to be what you are looking for:
>
> #define WIDEN2(x) L ## x
> #define WIDEN(x) WIDEN2(x)
>
> and the usage would be
>
> #define const1 "value"
> WIDEN(value)
>
> Don't ask me how it works, I think I know but as I said, I have not
> tested it.


Too bad. I think the OP asked for something like this:

#define const1 "value"
#define const1wide WIDEN(const1)

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


 
Reply With Quote
 
Karim
Guest
Posts: n/a
 
      01-08-2007
I was actually responding to Ondra`s suggestion. Thanks Erik, it does
work.


Victor Bazarov wrote:
> Erik Wikström wrote:
> > On 2007-01-08 22:31, Karim wrote:
> >> Hi,
> >>
> >> I have alot of constants that I need in regular char and in wchar_t
> >> form
> >>
> >> so instead of writing
> >>
> >> #define const1 "value1"
> >> #define const1wide L"value1"
> >>
> >> I want to make some other macro that would save time from duplicate
> >> definitions.
> >>
> >> so I was thinking of
> >>
> >> #define const1 "value1"
> >>
> >> and another macro
> >> #define WIDE(str) (##L str)

> >
> > I have not tested this but I found it in an example in the MSDN-
> > documentation and it seems to be what you are looking for:
> >
> > #define WIDEN2(x) L ## x
> > #define WIDEN(x) WIDEN2(x)
> >
> > and the usage would be
> >
> > #define const1 "value"
> > WIDEN(value)
> >
> > Don't ask me how it works, I think I know but as I said, I have not
> > tested it.

>
> Too bad. I think the OP asked for something like this:
>
> #define const1 "value"
> #define const1wide WIDEN(const1)
>
> V
> --
> Please remove capital 'A's when replying by e-mail
> I do not respond to top-posted replies, please don't ask


 
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
Dedicated Macro or Normal Macro? John Ortt Digital Photography 5 11-22-2005 12:43 PM
Macro lens on a camera with a macro setting??? mitchell.chris@gmail.com Digital Photography 2 09-28-2005 07:55 AM
in S.E. Asia : Canon EOS 300d with 100 macro ED vs. Nikon D70 with Nikon 105 macro ? J. Cod Digital Photography 0 09-29-2004 05:46 AM
#define macro to enclose an older macro with strings Dead RAM C++ 20 07-14-2004 10:58 AM
macro name from macro? D Senthil Kumar C Programming 1 09-21-2003 07:02 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57