line.html 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <html>
  2. <head>
  3. <title>BOOST_PP_LINE</title>
  4. <link rel="stylesheet" type="text/css" href="../styles.css">
  5. </head>
  6. <body>
  7. <div style="margin-left: 0px;">
  8. The <b>BOOST_PP_LINE</b> macro places notes encoded as line directives in the preprocessing output.
  9. </div>
  10. <h4>Usage</h4>
  11. <div class="code">
  12. #line <b>BOOST_PP_LINE</b>(<i>line</i>, <i>file</i>)
  13. </div>
  14. <h4>Arguments</h4>
  15. <dl>
  16. <dt>line</dt>
  17. <dd>
  18. The new line number of the trailing line.&nbsp;
  19. The predefined macro <i>__LINE__</i> is commonly used.
  20. </dd>
  21. <dt>file</dt>
  22. <dd>
  23. Typically the name of the current file.&nbsp;
  24. However, any informative text will work.&nbsp;
  25. This text is internally stringized, so quotation marks are unnecessary.
  26. </dd>
  27. </dl>
  28. <h4>Remarks</h4>
  29. <div>
  30. If the macro <b>BOOST_PP_CONFIG_EXTENDED_LINE_INFO</b> is defined as <i>1</i> and a <i>file-iteration</i>
  31. is in progress, this macro will automatically insert debugging information about the state of <i>file-iteration</i>.&nbsp;
  32. This information will show the all of the current iteration values with the inner most iteration last.
  33. </div>
  34. <div>
  35. This information is useful when errors might be spanning multiple iterations of the same source text.&nbsp;
  36. Finding any errors is sometimes less than straightforward.&nbsp;
  37. Use of this macro can provide information to make this much easier.&nbsp;
  38. For example, instead of getting several errors like this:
  39. <div><i>
  40. "file.hpp", line 2: error: expected a ";"<br>
  41. "file.hpp", line 4: error: improperly terminated macro invocation<br>
  42. </i></div>
  43. You might get something like this instead....
  44. <i><div>
  45. "file.hpp [1]", line 2: error: expected a ";"<br>
  46. "file.hpp [5]", line 4: error: improperly terminated macro invocation<br>
  47. </i></div>
  48. It is immediately evident that this error is spanning multiple iterations of the same source text.&nbsp;
  49. If it wasn't, the same errors would occur on each iteration.
  50. </div>
  51. <div>
  52. It must be noted however, that some compilers don't like filenames that aren't actually files.&nbsp;
  53. Those compilers typically issues warnings about the bad filename.&nbsp;
  54. This makes it a good idea to only define <b>BOOST_PP_CONFIG_EXTENDED_LINE_INFO</b> to <i>1</i> <i>only</i> when debugging.
  55. </div>
  56. <h4>See Also</h4>
  57. <ul>
  58. <li><a href="config_extended_line_info.html">BOOST_PP_CONFIG_EXTENDED_LINE_INFO</a></li>
  59. </ul>
  60. <h4>Requirements</h4>
  61. <div>
  62. <b>Header:</b> &nbsp;<a href="../headers/debug/line.html">&lt;boost/preprocessor/debug/line.hpp&gt;</a>
  63. </div>
  64. <h4>Sample Code</h4>
  65. <div><pre>
  66. // sample.cpp
  67. #if !defined(<a href="is_iterating.html">BOOST_PP_IS_ITERATING</a>)
  68. #define <a href="config_extended_line_info.html">BOOST_PP_CONFIG_EXTENDED_LINE_INFO</a> 1
  69. #include &lt;<a href="../headers/arithmetic/dec.html">boost/preprocessor/arithmetic/dec.hpp</a>&gt;
  70. #include &lt;<a href="../headers/cat.html">boost/preprocessor/cat.hpp</a>&gt;
  71. #include &lt;<a href="../headers/debug/line.html">boost/preprocessor/debug/line.hpp</a>&gt;
  72. #include &lt;<a href="../headers/iteration/iterate.html">boost/preprocessor/iteration/iterate.hpp</a>&gt;
  73. namespace sample {
  74. #define <a href="iteration_params_x.html">BOOST_PP_ITERATION_PARAMS_1</a> (3, (1, 5, "sample.cpp"))
  75. #include <a href="iterate.html">BOOST_PP_ITERATE</a>()
  76. } // sample
  77. int main(void) {
  78. return 0;
  79. }
  80. #else
  81. #line <a href="line.html">BOOST_PP_LINE</a>(1, sample.cpp)
  82. int <a href="cat.html">BOOST_PP_CAT</a>(x, <a href="iteration.html">BOOST_PP_ITERATION</a>())); // extra parenthesis
  83. struct <a href="cat.html">BOOST_PP_CAT</a>(s, <a href="dec.html">BOOST_PP_DEC</a>(<a href="iteration.html">BOOST_PP_ITERATION</a>()) {
  84. // missing a parenthesis
  85. // ...
  86. };
  87. #endif
  88. </pre></div>
  89. <hr size="1">
  90. <div style="margin-left: 0px;">
  91. <i>© Copyright <a href="http://www.housemarque.com" target="_top">Housemarque Oy</a> 2002</i>
  92. </br><i>© Copyright Paul Mensonides 2002</i>
  93. </div>
  94. <div style="margin-left: 0px;">
  95. <p><small>Distributed under the Boost Software License, Version 1.0. (See
  96. accompanying file <a href="../../../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or
  97. copy at <a href=
  98. "http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</small></p>
  99. </div>
  100. </body>
  101. </html>