Namespaces
Variants
Views
Actions

Filename and line information

From cppreference.com
< cpp‎ | preprocessor
Revision as of 12:57, 2 November 2012 by P12bot (Talk | contribs)

 
 
C++ language
General topics
Flow control
Conditional execution statements
Iteration statements
Jump statements
Functions
function declaration
lambda function declaration
function template
inline specifier
exception specifications (deprecated)
noexcept specifier (C++11)
Exceptions
Namespaces
Types
decltype specifier (C++11)
Specifiers
cv specifiers
storage duration specifiers
constexpr specifier (C++11)
auto specifier (C++11)
alignas specifier (C++11)
Initialization
Literals
Expressions
alternative representations
Utilities
Types
typedef declaration
type alias declaration (C++11)
attributes (C++11)
Casts
implicit conversions
const_cast conversion
static_cast conversion
dynamic_cast conversion
reinterpret_cast conversion
C-style and functional cast
Memory allocation
Classes
Class-specific function properties
Special member functions
Templates
class template
function template
template specialization
parameter packs (C++11)
Miscellaneous
Inline assembly
 
 

Includes other source file into current source file at the line immediately after the directive .

Contents

Syntax

#line Template:sparam (1)
#line Template:sparam "Template:sparam" (2)

Explanation

Changes the current preprocessor line number to Template:sparam. Expansions of the macro __LINE__ beyond this point will expand to Template:sparam plus the number of actual source code lines encountered since.

2) Also changes the current preprocessor file name to Template:sparam. Expansions of the macro __FILE__ from this point will produce Template:sparam.

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.

Notes

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.

Example

#include <cassert>
#define FNAME "test.cc"
int main()
{
#line 777 FNAME
        assert(2+2 == 5);
}

Output:

test: test.cc:777: int main(): Assertion `2+2 == 5' failed.