Objective-C 学习笔记5 预处理程序
2013-01-22 10:49
323 查看
预处理程序类似于简单替换,没有逻辑运算
1、预处理程序以#号开头,结尾没有任何符号,不换行,换行使用换行符号
2、预处理程序只是替换,没有计算、逻辑等运算
3、不能定义同一个常量多次,否则会报错
如下,OC中没有TRUE FALSE 可以定义一个
下面一个简单的示例(Code Blocks )代码
加入计算X2(y) 公式,计算一个数的平方
计算的优先级
条件编译
1、预处理程序以#号开头,结尾没有任何符号,不换行,换行使用换行符号
2、预处理程序只是替换,没有计算、逻辑等运算
3、不能定义同一个常量多次,否则会报错
如下,OC中没有TRUE FALSE 可以定义一个
#define TRUE 1 //定义遇到TRUE就替换为1 #define FALSE 0 //定义遇到FALSE 就替换为0 if(MAX==TRUE)//等于 if(MAX==1)
下面一个简单的示例(Code Blocks )代码
#import <Foundation/Foundation.h> #define P_MAX 99 #define P_MIN 9 #define PI 3.1415926 #define VERSION 1 int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!"); [pool drain]; //复制 int n=9; n=n*PI; if(n>P_MAX){ NSLog(@"oh no this max max"); } return 0; }
加入计算X2(y) 公式,计算一个数的平方
#import <Foundation/Foundation.h> #define P_MAX 99 #define P_MIN 9 #define PI 3.1415926 #define X2(y) y*y #define VERSION 1 int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!"); [pool drain]; //复制 int n=9; n=n*PI; if(n>P_MAX){ NSLog(@"oh no this max max"); } n=X2(100); NSLog(@"%d",n); return 0; }
计算的优先级
#import <Foundation/Foundation.h> #define P_MAX 99 #define P_MIN 9 #define PI 3.1415926 #define X2(y) y*y #define ADDXY(x,y) x+y #define VERSION 1 int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!"); [pool drain]; //复制 int n=9; n=n*PI; if(n>P_MAX){ NSLog(@"oh no this max max"); } //一个数的平方 n=X2(100); NSLog(@"%d",n); //优先级 n=ADDXY(1,5)*ADDXY(1,6);//等于x+y *x+y n=(ADDXY(1,5))*(ADDXY(1,6));//等于(x+y) *(x+y) //以上两个结果完全不一样 return 0; }
条件编译
#import <Foundation/Foundation.h> #define P_MIN 9 #define PI 3.1415926 #define X2(y) y*y #define ADDXY(x,y) x+y #define VERSION 1 #define DEBUG YES #ifdef DEBUG==YES #define P_MAX 999 #else #define P_MAX 99 #endif int main (int argc, const char *argv[]) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; NSLog(@"Hello World!"); [pool drain]; //复制 int n=9; n=n*PI; if(n>P_MAX){ NSLog(@"oh no this max max"); } //一个数的平方 n=X2(100); NSLog(@"%d",n); //优先级 n=ADDXY(1,5)*ADDXY(1,6);//等于x+y *x+y n=(ADDXY(1,5))*(ADDXY(1,6));//等于(x+y) *(x+y) //以上两个结果完全不一样 //条件编译 if(DEBUG==YES) { NSLog(@"yes print"); } return 0; }
相关文章推荐
- Objective-C 学习笔记 12 预处理程序
- [学习笔记—Objective-C]《Objective-C 程序设计 第6版》第十二章 预处理程序
- 黑马程序员——Objective-C程序设计(第4版)学习笔记之12-预处理程序——黑马 IOS 技术博客
- Objective-C学习笔记(三)——用Objective-C编写第一个程序:Hello,World!
- Object-C 学习笔记一-----最简单的objective-c程序
- 菜鸟C++精髓学习笔记--C++程序内部执行过程(预处理、编译、链接过程的作用)
- Objective-C基础学习笔记(一)-程序整体语法结构
- Objective-C基础学习笔记(一)-程序整体语法结构
- Objective-C学习笔记--第一个程序HelloWorld
- OC(Objective-C)学习笔记(二)--终端运行多OC程序
- Objective-C学习笔记(三)——用Objective-C编写第一个程序:Hello,World!
- 76.笔记 MySQL学习——C编写MySQL程序九预处理
- Objective-C 学习笔记 4 数据类型和表达式
- 跟踪学习Spring2.5笔记 -1- 第一个Spring程序
- 32位汇编语言学习笔记(23)--大小写转换程序2
- DirectShow 学习笔记< 一> -- 第一个程序
- Objective-C 学习笔记(Day 2)
- 汇编--学习笔记(十)-分支程序
- [Python学习笔记][第八章Python异常处理结构与程序调试]
- TCP聊天程序学习笔记