C预处理器

1.#define

在define中使用参数

注意:预处理器不进行计算,只进行字符串的替换

output:

这里的x+2,进行替换后变为x+2*x+2=14

这里的100/SQUARE(2)替换后变为 100/2*2=100

++x*++x 这里编译器将x自加两次后相乘

2.#运算符和##运算符

从上一个例子可以看到双引号里的宏是不起作用的,但是如何在字符串中包括宏参数(用#),这个过程叫字符串化;

和#一样,##运算符可以用于类函数宏的替换部分

e.

 Res:

3.可变宏:...和_ _VA_ARGS_ _

Res:

 3.#undef

作用:取消定义的一个给定的#define

#define LIMIT 400

#undef LIMIT

4.条件编译

#ifdef/#ifndef    #else(根据需要)   #endif(必须存在)

 1 #include<stdio.h>
 2 #define JUST_CHECKING
 3 #define LIMIT 4
 4 
 5 int main()
 6 {
 7    int i;
 8    int total;
 9 
10   for(int i=1;i<=LIMIT;i++)
11   {
12    total+=2*i*i+1;
13    #ifdef JUST_CHECKING
14          printf("i=%d,running total = %d \n",total);
15    #endif
16    }
17    printf("Grand total = %d \n",total);
18    return 0;
19 }

5.#line 和 #error

#line 1000     /*当前行号置为1000*/

#line 19 "cool.c"

6.#pragma      --编译指示

posted @ 2015-01-12 14:50  Xiaodigua  阅读(214)  评论(0编辑  收藏  举报