9.0/10 (6350 reviews)
Build Your Legal Living Will Effortlessly in Less than 10 Minutes. Our Guided Questionnaire Will Help You Personalize Your Living Will in Minutes.
A+ Highest Rating - Better Business Bureau
Search results
Preprocessor directive
- The #line directive in C is a preprocessor directive that lets you modify the compiler's reported values for the line number.
People also ask
What is a line directive in C?
What is a line directive?
What is a preprocessor directive in ANSI C?
How are directives handled in C?
What is a preprocessor line control directive?
Can a preprocessing directive cover more than one line?
Feb 7, 2010 · The #line directive in C is a preprocessor directive that lets you modify the compiler's reported values for the line number. Functionality: Changes the apparent line number of the current code section. Optionally updates the reported filename for compiler messages.
- Overview
- Remarks
- Example
The #line directive tells the preprocessor to set the compiler's reported values for the line number and filename to a given line number and 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 within the range from 0 to 2147483647, inclusive. Macro replacement can be used 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 (" "). If filename is omitted, the previous filename remains unchanged.
You can alter the source line number and filename by writing a #line directive. The #line directive sets the value for the line that immediately follows the directive in the source file. 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 (" ").
The following examples illustrate #line and the __LINE__ and __FILE__ macros.
In the first example, the line number is set to 10, then to 20, and the filename is changed to hello.cpp. 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 isn't true.
Oct 11, 2024 · There are 4 Main Types of Preprocessor Directives: Macros. File Inclusion. Conditional Compilation. Other directives. Let us now learn about each of these directives in detail. 1. Macros. In C, Macros are pieces of code in a program that is given some name.
A preprocessing directive of the form. # line digit-sequence new-line. causes the implementation to behave as if the following sequence of source lines begins with a source line that has a line number as specified by the digit sequence (interpreted as a decimal integer).
- #include. C has some features as part of the language and some others as part of a standard library, which is a repository of code that is available alongside every standard-conformant C compiler.
- #pragma. The pragma (pragmatic information) directive is part of the standard, but the meaning of any pragma depends on the software implementation of the standard that is used.
- #define. Each #define preprocessor instruction defines a macro. For example, #define PI 3.14159265358979323846 /* pi */ A macro defined with a space immediately after the name is called a constant or literal.
- macros. Macros aren't type-checked and so they do not evaluate arguments. Also, they do not obey scope properly, but simply take the string passed to them and replace each occurrence of the macro argument in the text of the macro with the actual string for that parameter (the code is literally copied into the location it was called from).
Nov 18, 2018 · C preprocessor is a Micro preprocessor which compiles the code before the compilation. List of all preprocessor directives: #include preprocessor directive. #define and #undef preprocessor directive. Parameterized Macros (Function like Macros) #ifdef, #ifndef and #endif preprocessor directive. #if…#elif…#else…#endif.
26.2 Directives. Preprocessing directives are lines in the program that start with ‘#’. Whitespace is allowed before and after the ‘#’. The ‘#’ is followed by an identifier, the directive name. It specifies the operation to perform. Here are a couple of examples: