标签:
1.macro definitions (#define, #undef)宏定义
#define TABLE_SIZE 100 int table1[TABLE_SIZE]; #undef TABLE_SIZE #define TABLE_SIZE 200 int table2[TABLE_SIZE];
在宏定义中 #是“字符串化”的意思。出现在宏定义中的#是把跟在后面的参数转换成一个字符串 #define str(x) #x cout << str(test); cout << "test"; “##”是一种分隔连接方式,它的作用是先分隔,然后进行强制连接 #define glue(a,b) a ## b glue(c,out) << "test"; cout << "test"; #define pinSET(var) ((var->BSRR) |= ((unsigned long)1<<(var##_Bit)))
2.Conditional inclusions (#ifdef, #ifndef, #if, #endif, #else and #elif)
#ifdef TABLE_SIZE int table[TABLE_SIZE]; #endif 如果定义了TABLE_SIZE,则有int table[TABLE_SIZE]; 如果没有,就没有int table[TABLE_SIZE]; #ifndef TABLE_SIZE #define TABLE_SIZE 100 #endif int table[TABLE_SIZE]; #if TABLE_SIZE>200 #undef TABLE_SIZE #define TABLE_SIZE 200 #elif TABLE_SIZE<50 #undef TABLE_SIZE #define TABLE_SIZE 50 #else #undef TABLE_SIZE #define TABLE_SIZE 100 #endif int table[TABLE_SIZE]; #if defined ARRAY_SIZE #define TABLE_SIZE ARRAY_SIZE #elif !defined BUFFER_SIZE #define TABLE_SIZE 128 #else #define TABLE_SIZE BUFFER_SIZE #endif
3.Line control (#line)
#line 100 /* 初始化行计数器* / main ( ) /* 行号100 */ { /* 行号101 */ printf("%d\n"_LINE_) ; /* 行号102 */ }
#line 20 "assigning variable" int a?;
4.Error directive (#error)
#ifndef __cplusplus #error A C++ compiler is required! #endif
5.Source file inclusion (#include)
#include <header> #include "file"
6.Pragma directive (#pragma)
根据编译器有不同的解释
7.Predefined macro names 以下这些名称是C++标准内定宏
__LINE__ 源代码中的当前行号
__FILE__ 源代码名字字符串
__DATE__ Mmm dd yyyy Apr 12 2016
__TIME__ hh:mm:ss 10:21:24
__cplusplus
__STD_HOSTED__
__STDC__
__STDC_VERSION__
__STDC_MB_MIGHT_NEQ_WC__
__STDC_ISO_10646__
__STDCPP_STRICT_POINTER_SAFETY__
__STDCPP_THREADS__
标签:
原文地址:http://www.cnblogs.com/hinice/p/5390618.html