Objective-c在宏里拼接字符串


//正式服务器
#define API_DOMAIN @"www.online.com"
//测试服务器
//#define DOMAINXX @"192.168.0.10"


#define API_SYSTEM @"http://"API_DOMAIN@"/system/"
#define API_USER @"http://"API_DOMAIN@"/user/"


 API_SYSTEM 宏展开后是: @"http://"@"www.online.com"@"/system/"
编译器会自动将字符中连接起来,目的实现。


c语言下的实现:
//正式服务器
#define API_DOMAIN "www.online.com"
//测试服务器
//#define DOMAINXX "192.168.0.10"


#define API_SYSTEM "http://"API_DOMAIN"/system/"

#define API_USER "http://"API_DOMAIN"/user/"

 


参考:
http://stackoverflow.com/questions/8844981/how-to-expand-a-macro-into-nsstring-without-using-any-string-concatenation-at-ru

http://stackoverflow.com/questions/798221/c-macros-to-create-strings

 

最后,感谢万能的google,万能的stackoverflow。


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM