What is compiler directive




















RemObjects Elements. Elements Docs » Compiler » Compiler Directives. Compiler Directives Compiler Directives are annotations in code that are not part of the actual code flow, but influence the behavior of the compiler, for example to control options or perform Conditional Compilation. Defines and Conditional Compilation The following directives allow you to set, unset and check for Defines for the purpose of Conditional Compilation.

See Conditional Compilation for details. The behavior dictated by a compiler directive takes effect as soon as the compiler reads the directive. The directive remains in effect for the rest of the compilation unless a different compiler directive specifies otherwise. A compiler directive in one file can therefore control compilation behavior in multiple description files.

Once defined, that name can be used in lieu of the characters. The name is then referred to as a macro. Any valid identifier, including keywords already in use, can be used as a name. The output of this example depends on whether you built the project on Debug or Release configuration mode. The following example shows you how to test for different target frameworks so you can use newer APIs when possible:. You use the following two preprocessor directives to define or undefine symbols for conditional compilation:.

You use define to define a symbol. When you use the symbol as the expression that's passed to the if directive, the expression will evaluate to true , as the following example shows:.

Constants in C are best defined as static members of a class or struct. If you have several such constants, consider creating a separate "Constants" class to hold them.

Symbols can be used to specify conditions for compilation. You can test for the symbol with either if or elif. You can also use the ConditionalAttribute to perform conditional compilation. You can define a symbol, but you can't assign a value to a symbol. The define directive must appear in the file before you use any instructions that aren't also preprocessor directives.

You can define regions of code that can be collapsed in an outline using the following two preprocessor directives:. In longer code files, it's convenient to collapse or hide one or more regions so that you can focus on the part of the file that you're currently working on.

The following example shows how to define a region:. A region block must be terminated with an endregion directive. A region block can't overlap with an if block. However, a region block can be nested in an if block, and an if block can be nested in a region block. You instruct the compiler to generate user-defined compiler errors and warnings, and control line information using the following directives:. The compiler treats error version in a special way and reports a compiler error, CS, with a message containing the used compiler and language versions.

The following example shows how to report two warnings associated with line numbers. The line directive forces the next line's number to be although the default is 6 , and until the next line directive, the filename will be reported as "Special".

The line default directive returns the line numbering to its default numbering, which counts the lines that were renumbered by the previous directive. The line directive might be used in an automated, intermediate step in the build process. For example, if lines were removed from the original source code file, but you still wanted the compiler to generate output based on the original line numbering in the file, you could remove lines and then simulate the original line numbering with line.

The line hidden directive hides the successive lines from the debugger, such that when the developer steps through the code, any lines between a line hidden and the next line directive assuming that it isn't another line hidden directive will be stepped over.

This option can also be used to allow ASP. NET to differentiate between user-defined and machine-generated code. Although ASP. NET is the primary consumer of this feature, it's likely that more source generators will make use of it. A line hidden directive doesn't affect file names or line numbers in error reporting. That is, if the compiler finds an error in a hidden block, the compiler will report the current file name and line number of the error.

The line filename directive specifies the file name you want to appear in the compiler output. By default, the actual name of the source code file is used. The file name must be in double quotation marks "" and must be preceded by a line number. Domain-specific languages DSLs typically use this format to provide a better mapping from the source file to the generated C output.

To see more examples of this format, see the feature specification in the section on examples.



0コメント

  • 1000 / 1000