zoukankan      html  css  js  c++  java
  • C语言预处理命令

    1.#error Directive (C/C++)

    The #error directive emits a user-specified error message at compile time and then terminates the compilation.

    #error    token-string

    The error message that this directive emits includes the token-string parameter. The token-string parameter is not subject to macro expansion. This directive is most useful during preprocessing for notifying the developer of a program inconsistency or the violation of a constraint. The following example demonstrates error processing during preprocessing:

    #if    !defined(__cplusplus)
    #error     C++ compiler required.
    #endif

    2.#line Directive (C/C++)

    The #line directive tells the preprocessor to change the compiler's internally stored line number and filename to a given line number and filename.

    #line    digit-sequence ["filename"]

    The compiler uses the line number and optional filename to refer to errors that it finds during compilation. The line number usually refers to the current input line, and the filename refers to the current input file. The line number is incremented after each line is processed.

    The digit-sequence value can be any integer constant. Macro replacement can be performed on the preprocessing tokens, but the result must evaluate to the correct syntax. The filename can be any combination of characters and must be enclosed in double quotation marks (" "). Iffilename is omitted, the previous filename remains unchanged.

    You can alter the source line number and filename by writing a #line directive. The translator uses the line number and filename to determine the values of the predefined macros __FILE__ and __LINE__. You can use these macros to insert self-descriptive error messages into the program text. For more information on these predefined macros, see Predefined Macros.

    The __FILE__ macro expands to a string whose contents are the filename, surrounded by double quotation marks (" ").

    If you change the line number and filename, the compiler ignores the previous values and continues processing with the new values. The #linedirective is typically used by program generators to cause error messages to refer to the original source file instead of to the generated program.

    The following examples illustrate #line and the __LINE__ and __FILE__ macros.

    In this statement, the internally stored line number is set to 151 and the filename is changed to copy.c.

    #line    151 "copy.c"

    In this example, the macro ASSERT uses the predefined macros __LINE__ and __FILE__ to print an error message about the source file if a given "assertion" is not true.

    #define ASSERT(cond)
    if( !(cond) )
    {printf( "assertion error line %d, file(%s)
    ", 
    __LINE__, __FILE__ );}

    3.#undef Directive (C/C++)

    Removes (undefines) a name previously created with #define.

    #undef    identifier

    The #undef directive removes the current definition of identifier. Consequently, subsequent occurrences of identifier are ignored by the preprocessor. To remove a macro definition using #undef, give only the macro identifier ; do not give a parameter list.

    You can also apply the #undef directive to an identifier that has no previous definition. This ensures that the identifier is undefined. Macro replacement is not performed within #undef statements.

    The #undef directive is typically paired with a #define directive to create a region in a source program in which an identifier has a special meaning. For example, a specific function of the source program can use manifest constants to define environment-specific values that do not affect the rest of the program. The #undef directive also works with the #if directive to control conditional compilation of the source program.See The #if, #elif, #else, and #endif Directives for more information.

    In the following example, the #undef directive removes definitions of a symbolic constant and a macro. Note that only the identifier of the macro is given.

    #define WIDTH 80
    #define ADD( X, Y ) ((X) + (Y))
    .
    .
    .
    #undef WIDTH
    #undef ADD

    Microsoft Specific

    Macros can be undefined from the command line using the /U option, followed by the macro names to be undefined. The effect of issuing this command is equivalent to a sequence of #undef macro-name statements at the beginning of the file.

    END Microsoft Specific

    参考:

    http://msdn.microsoft.com/zh-cn/library/3sxhs2ty.aspx

    assert()函数用法总结

  • 相关阅读:
    jsp中添加弹窗口并且实现向后台双向传递数据
    hql中or的用法(代替union)
    hql中in的用法
    spring中的定时任务调度用例
    JS如何将UTC格式时间转本地格式
    HttpSession与Hibernate中Session的区别
    adaptive hash index
    InnoDB Double write
    int(M)与int
    MySQL库目录下db.opt文件的作用
  • 原文地址:https://www.cnblogs.com/Camilo/p/3773190.html
Copyright © 2011-2022 走看看