⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 line-control.html

📁 gcc手册
💻 HTML
字号:
<html lang="en">

<head>

<title>The C Preprocessor</title>

<meta http-equiv="Content-Type" content="text/html">

<meta name="description" content="The C Preprocessor">

<meta name="generator" content="makeinfo 4.3">

<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">

<!--

Copyright &copy; 1987, 1989, 1991, 1992, 1993, 1994, 1995, 1996,

1997, 1998, 1999, 2000, 2001, 2002, 2003

Free Software Foundation, Inc.



   <p>Permission is granted to copy, distribute and/or modify this document

under the terms of the GNU Free Documentation License, Version 1.1 or

any later version published by the Free Software Foundation.  A copy of

the license is included in the

section entitled "GNU Free Documentation License".



   <p>This manual contains no Invariant Sections.  The Front-Cover Texts are

(a) (see below), and the Back-Cover Texts are (b) (see below).



   <p>(a) The FSF's Front-Cover Text is:



   <p>A GNU Manual



   <p>(b) The FSF's Back-Cover Text is:



   <p>You have freedom to copy and modify this GNU Manual, like GNU

     software.  Copies published by the Free Software Foundation raise

     funds for GNU development. 

-->

</head>

<body>

<div class="node">

<p>

Node:<a name="Line%20Control">Line Control</a>,

Next:<a rel="next" accesskey="n" href="Pragmas.html#Pragmas">Pragmas</a>,

Previous:<a rel="previous" accesskey="p" href="Diagnostics.html#Diagnostics">Diagnostics</a>,

Up:<a rel="up" accesskey="u" href="index.html#Top">Top</a>

<hr><br>

</div>



<h2 class="chapter">Line Control</h2>



   <p>The C preprocessor informs the C compiler of the location in your source

code where each token came from.  Presently, this is just the file name

and line number.  All the tokens resulting from macro expansion are

reported as having appeared on the line of the source file where the

outermost macro was used.  We intend to be more accurate in the future.



   <p>If you write a program which generates source code, such as the

<code>bison</code> parser generator, you may want to adjust the preprocessor's

notion of the current file name and line number by hand.  Parts of the

output from <code>bison</code> are generated from scratch, other parts come

from a standard parser file.  The rest are copied verbatim from

<code>bison</code>'s input.  You would like compiler error messages and

symbolic debuggers to be able to refer to <code>bison</code>'s input file.



   <p><code>bison</code> or any such program can arrange this by writing

<code>#line</code> directives into the output file.  <code>#line</code> is a

directive that specifies the original line number and source file name

for subsequent input in the current preprocessor input file. 

<code>#line</code> has three variants:



     <dl>

<dt><code>#line </code><var>linenum</var><code></code>

     <dd><var>linenum</var> is a non-negative decimal integer constant.  It specifies

the line number which should be reported for the following line of

input.  Subsequent lines are counted from <var>linenum</var>.



     <br><dt><code>#line </code><var>linenum</var><code> </code><var>filename</var><code></code>

     <dd><var>linenum</var> is the same as for the first form, and has the same

effect.  In addition, <var>filename</var> is a string constant.  The

following line and all subsequent lines are reported to come from the

file it specifies, until something else happens to change that. 

<var>filename</var> is interpreted according to the normal rules for a string

constant: backslash escapes are interpreted.  This is different from

<code>#include</code>.



     <p>Previous versions of CPP did not interpret escapes in <code>#line</code>;

we have changed it because the standard requires they be interpreted,

and most other compilers do.



     <br><dt><code>#line </code><var>anything else</var><code></code>

     <dd><var>anything else</var> is checked for macro calls, which are expanded. 

The result should match one of the above two forms. 

</dl>



   <p><code>#line</code> directives alter the results of the <code>__FILE__</code> and

<code>__LINE__</code> predefined macros from that point on.  See <a href="Standard-Predefined-Macros.html#Standard%20Predefined%20Macros">Standard Predefined Macros</a>.  They do not have any effect on <code>#include</code>'s

idea of the directory containing the current file.  This is a change

from GCC 2.95.  Previously, a file reading



<pre class="smallexample">     #line 1 "../src/gram.y"

     #include "gram.h"

     </pre>



   <p>would search for <code>gram.h</code> in <code>../src</code>, then the <code>-I</code>

chain; the directory containing the physical source file would not be

searched.  In GCC 3.0 and later, the <code>#include</code> is not affected by

the presence of a <code>#line</code> referring to a different directory.



   <p>We made this change because the old behavior caused problems when

generated source files were transported between machines.  For instance,

it is common practice to ship generated parsers with a source release,

so that people building the distribution do not need to have yacc or

Bison installed.  These files frequently have <code>#line</code> directives

referring to the directory tree of the system where the distribution was

created.  If GCC tries to search for headers in those directories, the

build is likely to fail.



   <p>The new behavior can cause failures too, if the generated file is not

in the same directory as its source and it attempts to include a header

which would be visible searching from the directory containing the

source file.  However, this problem is easily solved with an additional

<code>-I</code> switch on the command line.  The failures caused by the old

semantics could sometimes be corrected only by editing the generated

files, which is difficult and error-prone.



   </body></html>



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -