Chinaunix首页 | 论坛 | 博客
  • 博客访问: 177975
  • 博文数量: 39
  • 博客积分: 351
  • 博客等级: 一等列兵
  • 技术积分: 298
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-03 10:56
文章分类

全部博文(39)

文章存档

2013年(8)

2012年(31)

分类: LINUX

2012-09-25 10:02:34

预编译指令:
DirectiveDescription
#defineDefines a name as a macro that the preprocessor will expand in the code every place the name is used.
#elifProvides an alternative expression to be evaluated by an #if directive.
#elseProvides an alternative set of code to be compiled if an #if, #ifdef, or #ifndef is false.
#errorProduces an error message and halts the preprocessor.
#ifCompiles the code between this directive and its matching #endif only if evaluating an arithmetic expression results in a nonzero value.
#ifdefCompiles the code between this directive and its matching #endif only if the named macro has been defined.
#ifndefCompiles the code between this directive and its matching #endif only if the named macro has not been defined.
#includeSearches through a list of directories until it finds the named file; then it inserts the contents of the file just as if it had been inserted by a text editor.
#include_nextThe same as #include, but this directive begins the search for the file in the directory following the one in which the current file was found.
#lineSpecifies the line number, and possibly the file name, that is reported to the compiler to be used to create debugging information in the object file.
#pragmaA standard method of providing additional information that may be specific to one compiler or one platform.
#undefRemoves a definition previously created by a #define directive.
#warningProduces a warning message from the preprocessor.
##The concatenation operator, which can be used inside a macro to combine two strings into one.

说明:#define使用注意:
1、形如#define ADD(a, b) ((a)+(b))这样的宏定义,要注意括号的使用;
2、带参数的宏,参数列表括号与宏名字之间不能有空格;
3、要将一个宏声明为多行,行尾需加“\”,例如:
  1. #define PRINT(...) \   
  2.       fprintf(stdout, __VA_ARGS__)   
    (注意:这里的__VA_ARGS__需要C99标准的支持)
4、使用#号可以将数字转换为字符串,例如:
  1. #define PRINT_AGE(age) printf("I am " #age " years old.\n")  
当你使用PRINT_AGE(24);时回打印出:I am 24 years old.

5、两个井号##可以连接两个字符串。

#error与#warning#error指令会使预编译处理器发出一条致命的错误,并中止;
#warning指令会使预编译处理器产生一条警告,随后继续处理后续任务。
#line#line指令可以改变#line指令所在行的行号,以及所在的文件名,从而影响__LINE__、__FILE__的值,例如有个main.c文件,内容如下:
  1. #include   
  2. #line 100 "test.c"  
  3. int main(int argc, char *argv[])  
  4. {  
  5.     printf("File: %s, Line: %d\n", __FILE__, __LINE__);  
  6.     return 0;  
  7. }  
    编译链接后,执行生成的可执行文件,结果输出:File: test.c, Line: 103
    (暂不知该指令的应用具体有何意义)

预编译宏:
MacroDescription
__FILE__A quoted string containing the name of the source file in which the macro is used. Also see __BASE_FILE__.
__func__The same as __FUNCTION__.
__FUNCTION__A quoted string containing the name of the current function.
__GNUC__This macro is always defined as the major version number of the compiler. For example, if the compiler version number is 3.1.2, this macro is defined as 3.
__GNUC_MINOR__This macro is always defined as the minor version number of the compiler. For example, if the compiler version number is 3.1.2, this macro is defined as 1.
__GNUC_PATCHLEVEL__This macro is always defined as the revision level of the compiler. For example, if the compiler version number is 3.1.2, this macro is defined as 2.
__GNUG__Defined by the C++ compiler. This macro is defined whenever both __cplusplus and __GNUC__ are also defined.
__INCLUDE_LEVEL__An integer value specifying the current depth level of the include file. The value at the base file (the one specified on the command ine) is 0 and is increased by 1 inside each file input by an #include directive.
__LINE__The line number of the file in which the macro is used.
__NO_INLINE__This macro is defined as 1 when no functions are to be expanded inline, either because there is no optimization or inlining has been specifically disabled.
__OBJC__This macro is defined as 1 if the program is being compiled as Objective-C.
__OPTIMIZE__This macro is defined as 1 whenever any level of optimization has been specified.
__OPTIMIZE_SIZE__This macro is defined as 1 if optimization is set for size instead of speed.
__REGISTER_PREFIX__This macro is a token (not a string) that is the prefix for register names. It can be used to write assembly language that’s portable to more than one environment.
__STDC__Defined as 1 to indicate that the compiler is conforming to standard C. This macro is not defined when compiling C++ or Objective-C, and it is also not defined when the-traditional option is specified.
__STDC_HOSTED__Defined as 1 to signify a “hosted” environment (one that has the complete standard C library available).
__STDC_VERSION__A long integer specifying the standards version number in terms of its year and month. For example, the 1999 revision of the standard is the value 199901L. This macro is not defined when compiling C++ or Objective-C, and it is also not defined when the -traditional option is specified.
__STRICT_ANSI__Defined if and only if either -ansi or -std has been specified on the command line. It is used in the GNU header files to restrict the definitions to those defined in the standard.
__TIME__A seven-character quoted string containing the time the program was compiled. It has the form "18:10:34".
__USER_LABEL_PREFIX__This macro is a token (not a string) that is used as the prefix on symbols in assembly language. The token varies depending on the platform, but it’s usually an underscore character.
__USING_SJLJ_EXCEPTIONS__This macro is defined as 1 if the mechanism for handling exceptions is setjmp and longjmp.
__VERSION__The complete version number. There is no specific format for this information, but it will at least include the major and minor release numbers.

阅读(7185) | 评论(0) | 转发(1) |
给主人留下些什么吧!~~