宏中的#的功能是将其后面的宏参数进行字符串化操作(Stringizing operator),简单说就是在它援用的宏变量的左右各加上1个双引号。
如定义好#define STRING(x) #x以后,下面2条语句就等价。
char *pChar = "hello";
char *pChar = STRING(hello);
还有1个#@是加单引号(Charizing Operator)
#define makechar(x) #@x
char ch = makechar(b);与char ch = ‘b’;等价。
但有小问题要注意,宏中遇到#或##时就不会再展开宏中嵌套的宏了。甚么意思了?比如使用char *pChar =STRING(__FILE__);虽然__FILE__本身也是1个宏,但编译器不会展开它,所以pChar将指向"__FILE__"而不是你要想的形如"D:XXX.cpp"的源文件名称。因此要加1个中间转换宏,先将__FILE__解析成"D:XXX.cpp"字符串。
定义以下所示2个宏:
#define _STRING(x) #x
#define STRING(x) _STRING(x)
再调用下面语句将输出带""的源文件路径
char* pChar = STRING(__FILE__);
printf("%s %s
", pChar, __FILE__);
可以比较下STRING(__FILE__)与__FILE__的不同,前将带双引号,后1个没有双引号。
本文参考:
波比源码 » C Language Study – how to use '#'
levaquin 250mg drug purchase levofloxacin
avodart order online avodart medication cost zofran 4mg
ampicillin 250mg tablet bactrim sale buy erythromycin 250mg without prescription
order sildenafil pill nolvadex 20mg canada buy methocarbamol 500mg sale
buy sildenafil 50mg sale aurogra 50mg usa estradiol 2mg oral
order lamictal pills order mebendazole generic order retin gel sale
indocin 50mg ca brand trimox 250mg buy amoxicillin online cheap
order ramipril 5mg pills temovate price azelastine usa
purchase buspar sale amiodarone cheap oxybutynin 5mg pill
order fosamax 70mg without prescription order fosamax 70mg pepcid medication
imdur 20mg cheap buy telmisartan pill order micardis 80mg
molnunat 200mg tablet buy lansoprazole 30mg online buy lansoprazole 15mg
tadalafil 20mg pills Mail order cialis viagra 100mg cost
modafinil cheap pharmacy online ivermectina online
nootropil 800mg sale buy sildenafil 50mg for sale viagra overnight shipping
purchase zithromax without prescription order neurontin pill order neurontin online
aralen price order cenforce generic baricitinib 2mg uk
glycomet brand order metformin 500mg pill order cialis 5mg sale
genuine viagra sildenafil next day delivery cost lisinopril
lopressor 50mg price brand vardenafil 10mg order levitra 10mg online cheap
paper writer academia writers roulette free
cialis prices sildenafil 100mg pills viagra 100mg uk
oral triamcinolone 4mg buy generic triamcinolone 10mg oral clarinex 5mg
buy priligy for sale buy priligy 30mg generic synthroid 150mcg cheap
buy cialis 20mg sale cialis 40mg oral buy viagra 50mg without prescription
buy xenical 120mg pills buy acyclovir 800mg for sale cheap acyclovir 400mg
buy tadalafil buy inderal 20mg online cheap purchase plavix generic
zyloprim 300mg pill zyloprim 300mg without prescription brand zetia
buy generic motilium 10mg domperidone 10mg us cyclobenzaprine 15mg us
buy generic sumatriptan 25mg imitrex 50mg price order avodart for sale
buy keflex 250mg for sale erythromycin 250mg cost cost erythromycin
buy cialis 5mg online cheap order cialis 10mg without prescription buy sildenafil 100mg
ceftin 250mg tablet cefuroxime 500mg over the counter purchase robaxin pills
desyrel 100mg cheap aurogra online buy aurogra 50mg oral