English 中文(简体)
• 如何利用C的宏观方法压缩两个宽体?
原标题:How to concatenate two wide strings using a macro in C?
  • 时间:2010-09-30 13:43:20
  •  标签:
  • c
  • macros

我想用宏观方法压缩两条宽体,因此我界定了一些宏观:

#define VERSION_MAJOR 1
#define VERSION_MINOR 1
#define VERSION_BUILD 0
#define VERSION_REVISION 0


#define _STR(s) #s
#define STR(s) _STR(s)

#define _TOWSTRING(x) L##x
#define TOWSTRING(x) _TOWSTRING(x)


//http://stackoverflow.com/questions/240353/convert-a-preprocessor-token-to-a-string
#define PRODUCT_ELASTOS_VERSION STR(VERSION_MAJOR) "." 
                                STR(VERSION_MINOR) "." 
                                STR(VERSION_BUILD) "." 
                                STR(VERSION_REVISION)

now I want to define a new macro PRODUCT_ELASTOS_VERSION_W using macro PRODUCT_ELASTOS_VERSION, it s value should be L"1.1.0.0". so how can I define this macro? TOWSTRING(PRODUCT_ELASTOS_VERSION) is wrong answer.

And if I want to concatenating string, how should I write? L"v" TOWSTRING(PRODUCT_ELASTOS_VERSION) cann t get wide string L"v1.1.0.0".

问题回答

首先,PRODUCT_ELASTOS_VERSION并不扩大至“1.1.0.0”。

"1" "." "1" "." "0" "." "0"

保持同一结构,你可以确定另一个可扩展至更广阔的识别标志

L"1" L"." L"1" L"." L"0" L"." L"0"

iii

#define _LSTR(s) L ## #s
#define LSTR(s) _LSTR(s)

#define ANOTHER_IDENTIFIER LSTR(VERSION_MAJOR) L"." 
                           LSTR(VERSION_MINOR) L"." 
                           LSTR(VERSION_BUILD) L"." 
                           LSTR(VERSION_REVISION)




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签