宏定义字符串的拼接

宏定义字符串的拼接偶然发现下面形式的代码,觉得很陌生,先上代码:1/*Filepaths2*/34#defineCMEFS_PH_DIR”/mmode/cmph/”5…6#defineCMEFS_UIM_DIR”/nv/item_files/modem/uim/”78/*9**EFStablet…

大家好,欢迎来到IT知识分享网。

偶然发现下面形式的代码,觉得很陌生,先上代码:

 1 /* Filepaths
 2 */
 3 
 4 #define CMEFS_PH_DIR        "/mmode/cmph/"
 5 ...
 6 #define CMEFS_UIM_DIR       "/nv/item_files/modem/uim/"
 7 
 8 /*
 9 ** EFS table that maps EFS Id to filename
10 */
11 static const cmefs_tbl_s_type cmefs_tbl[] =
12 {
13   { CMEFS_USER_NET_SEL_MODE_PREF_NAM_1, CMEFS_PH_DIR "user_net_sel_mode_nam_1" },
14   { CMEFS_USER_NET_SEL_MODE_PREF_NAM_2, CMEFS_PH_DIR "user_net_sel_mode_nam_2" },
15 ...

 CMEFS_PH_DIR “user_net_sel_mode_nam_1” 这样的代码以前没有遇见过,查阅相关资料,做了以下实验:

 (1)

1 #include <stdio.h>
2 #define CMEFS_PH_DIR        "/mmode/cmph/"
3 
4 void main()
5 {
6   printf("拼接后的字符串为: %s\n",CMEFS_PH_DIR "user_net_sel_mode_nam_1");
7 }

输出结果:

宏定义字符串的拼接

(2) 

1 #include <stdio.h>
2 
3 void main()
4 {
5   char *sub_string = "/mmode/cmph/" "user_net_sel_mode_nam_1";
6   printf("拼接后的字符串为: %s\n",sub_string );
7 }

输出结果与(1)相同。

(3)

1 #include <stdio.h>
2 #define CMEFS_PH_DIR        "/mmode/cmph/"
3 #define SUB_STRING          "user_net_sel_mode_nam_1"
4 
5 void main()
6 {
7   printf("拼接后的字符串为: %s\n",CMEFS_PH_DIR SUB_STRING);
8 }

输出结果与(1)相同。

 以上都可以定义字符串以及用宏定义拼接相关的字符串。

转载于:https://www.cnblogs.com/xiangxyq/p/7744633.html

免责声明:本站所有文章内容,图片,视频等均是来源于用户投稿和互联网及文摘转载整编而成,不代表本站观点,不承担相关法律责任。其著作权各归其原作者或其出版社所有。如发现本站有涉嫌抄袭侵权/违法违规的内容,侵犯到您的权益,请在线联系站长,一经查实,本站将立刻删除。 本文来自网络,若有侵权,请联系删除,如若转载,请注明出处:https://yundeesoft.com/14021.html

(0)

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

关注微信