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 provided des the token-string parameter. the token-string parameter is not subject to macro expansion. this directive is most useful during preprocessing for policying 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.
TheDigit-sequenceValue can be any integer constant. Macro replacement can be completed MED on the preprocessing tokens, but the result must evaluate to the correct syntax.FilenameCan be any combination of characters and must be enclosed in double quotation marks (""). IfFilenameIs 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 implements strate # line and_ 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)\n", \__LINE__, __FILE__ );}
3. # undef Directive (C/C ++)
Removes (undefines) a name previusly created with # define.
#undef identifier
The # undef directive removes the current definitionIdentifier. Consequently, subsequent occurrencesIdentifierAre ignored by the preprocessor. To remove a macro definition using # undef, give only the macroIdentifier; 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 supported med within # undef statements.
The # undef directive is typically too red with a # define direve ve 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 direves VES 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 # undefMacro-nameStatements at the beginning of the file.
END Microsoft Specific
Http://msdn.microsoft.com/zh-cn/library/3sxhs2ty.aspx