[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
在宏定义中,我们会看见一些#和##,#的作用是把后面的参数字符串化,切记,运用#和##的前提必须是带参数的宏定义,而##是相当于一个连接符,把参数两边的连接接起来。
下面是#的例子:
#define name(x) #x
我们定义了这样的一个宏,此时,如果用name(a)来调用它,因为#是把后面的参数字符串化,所以此时应该是字符串的“a”,也就是相当于给参数两边加了双引号
下面是##例子:
#define cons(a,b) a##b
用cons(2,3)调用他,此时应该是23,因为##起到了连接的作用。
#与##的注意事项:
如果宏参数是另一个宏时,而且有#和##时,此时的宏只会展开当前的这个宏,而不会展开宏参数里面得那个宏,也就是只是对当前宏有效,比如:
#define A 2 #define con(x) #x
如果我们用con(A)来调用它,因为A是另一个宏,所以con这个宏的参数是另一个宏,而且遇见了#,所以他替换完之后,是#A,输出得就是“A”。而不是我们预想的“2”。运行结果如下:
##与这个也是相同的意思,而要解决这个,我们只需在定义一个宏,让这个宏把所有的参数都转换完就可以,如下:
#define A 2 #define con(x) #x #define _con(x) con(x)//转换宏
我们这样调用这个宏,_con(A)这样就可以转换了,因为_con(A)会被转化成con(A),而此时又因为_con(A)没有#,所以会被完全替换成con(2),而con(2)又会被替换成#2,而#的作用就是在参数两边加双引号,所以结果就是“2”。运行结果如下:
所以,这个地方我们应该注意一下。##和#一样,当宏参数是另一个宏时,要定义一个转换宏。
希望大家能够喜欢,能够多多支持,如果你学到了的话,就点一下赞吧!!!!