General topics | ||||||||||||||||
Flow control | ||||||||||||||||
Conditional execution statements | ||||||||||||||||
Iteration statements (loops) | ||||||||||||||||
Jump statements | ||||||||||||||||
Functions | ||||||||||||||||
Function declaration | ||||||||||||||||
Lambda function expression | ||||||||||||||||
inline specifier | ||||||||||||||||
Dynamic exception specifications(until C++17*) | ||||||||||||||||
noexcept specifier(C++11) | ||||||||||||||||
Exceptions | ||||||||||||||||
Namespaces | ||||||||||||||||
Types | ||||||||||||||||
Specifiers | ||||||||||||||||
| ||||||||||||||||
Storage duration specifiers | ||||||||||||||||
Initialization | ||||||||||||||||
Expressions | ||||||||||||||||
Alternative representations | ||||||||||||||||
Literals | ||||||||||||||||
Boolean -Integer -Floating-point | ||||||||||||||||
Character -String -nullptr(C++11) | ||||||||||||||||
User-defined(C++11) | ||||||||||||||||
Utilities | ||||||||||||||||
Attributes(C++11) | ||||||||||||||||
Types | ||||||||||||||||
typedef declaration | ||||||||||||||||
Type alias declaration(C++11) | ||||||||||||||||
Casts | ||||||||||||||||
Memory allocation | ||||||||||||||||
Classes | ||||||||||||||||
Class-specific function properties | ||||||||||||||||
| ||||||||||||||||
Special member functions | ||||||||||||||||
Templates | ||||||||||||||||
Miscellaneous | ||||||||||||||||
(C++23)(C++23) | ||||
(C++17) | ||||
(C++23) | ||||
(C++11) | ||||
#line | ||||
(C++26) |
Changes the source code's line number and, optionally, the current file name, in the preprocessor.
Contents |
#line lineno | (1) | ||||||||
#line lineno" filename" | (2) | ||||||||
1) Changes the current preprocessor line number tolineno. Expansions of the macro__LINE__ beyond this point will expand tolineno plus the number of actual source code lines encountered since.
2) Also changes the current preprocessor file name tofilename. Expansions of the macro__FILE__ from this point will producefilename.
Any preprocessing tokens (macro constants or expressions) are permitted as arguments to#line as long as they expand to a valid decimal integer optionally following a valid character string.
lineno must be a sequence of at least one decimal digit (the program is ill-formed, otherwise) and is always interpreted as decimal (even if it starts with0
).
Iflineno is0
or greater than32767
(until C++11)2147483647
(since C++11), the behavior is undefined.
This directive is used by some automatic code generation tools which produce C++ source files from a file written in another language. In that case,#line directives may be inserted in the generated C++ file referencing line numbers and the file name of the original (human-editable) source file.
#include <cassert>#define FNAME "test.cc"int main(){#line 777 FNAMEassert(2+2==5);}
Possible output:
test: test.cc:777: int main(): Assertion `2+2 == 5' failed.
(C++20) | a class representing information about the source code, such as file names, line numbers, and function names (class)[edit] |
C documentation forFilename and line information |