根据不同情况编译不同代码、产生不同目标文件的机制,称为条件编译
有这些预处理命令:#if、#elif、#else #endif ;#ifdef #else #endif
PHP源码:
#ifdef SERIALIZE_HEADERS //如果存在宏定义SERIALIZE_HEADERS # define VEC_FREE() smart_str_free(&vec_str) //宏定义VEC_FREE() #else //如果不存在 # define VEC_FREE() do {} while (0) //宏定义空操作 #endif #ifdef DEBUG //如果存在宏定义DEBUG # define LOG_MSG printf //宏定义LOG_MSG #else //如果不存在 # define LOG_MSG(...) //宏定义空操作 #endif
练习:
#if _WIN32 printf("windows系统 \n"); #elif __linux__ printf("linux系统 \n"); #else printf("其他系统 \n"); #endif #ifdef N printf("存在宏定义N \n"); #else printf("不存在宏定义N \n"); #endif
如对本文有疑问, 点击进行留言回复!!
如何去设计前端框架能力?星巴克消息开放项目从0到1,从点到面的思考
PHP制作日历,实现在1970年到2020年之间的任何一个月份的输出。上半部分
网友评论