Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      Filename and line information

      From cppreference.com
      <c‎ |preprocessor
       
       
       
       

      Changes the current line number and file name in the preprocessor.

      Contents

      [edit]Syntax

      #linelineno (1)
      #linelineno"filename" (2)

      [edit]Explanation

      1) Changes the current preprocessor line number tolineno. Occurrences 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. Occurrences of the macro__FILE__ beyond 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 C99)2147483647(since C99), the behavior is undefined.

      [edit]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.

      The line number following the directive#line __LINE__ is unspecified (there are two possible values that__LINE__ can expand to in this case: number of endlines seen so far, or number of endlines seen so far plus the endline that ends the#line directive). This is the result ofDR 464, which applies retroactively.

      [edit]Example

      Run this code
      #include <assert.h>#define FNAME "test.c"int main(void){#line 777 FNAMEassert(2+2==5);}

      Possible output:

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

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 6.10.4 Line control (p: 126)
      • J.1 Unspecified behavior
      • C11 standard (ISO/IEC 9899:2011):
      • 6.10.4 Line control (p: 173)
      • C99 standard (ISO/IEC 9899:1999):
      • 6.10.4 Line control (p: 158)
      • C89/C90 standard (ISO/IEC 9899:1990):
      • 3.8.4 Line control

      [edit]See also

      C++ documentation forFilename and line information
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/preprocessor/line&oldid=139846"

      [8]ページ先頭

      ©2009-2025 Movatter.jp