SEC15_LINE.hss 1.9 KB

1234567891011121314151617181920212223242526272829303132333435
  1. [Main]
  2. Title=__LINE__
  3. [Top]
  4. This macro expands to the current input line number, in the form of a
  5. decimal integer constant. While we call it a predefined macro, it's
  6. a pretty strange macro, since its "definition" changes with each
  7. new line of source code.
  8. <BR><BR>
  9. <CODE><A HREF="$$LINK(SEC15_FILE)">__FILE__</A></CODE> and <CODE>__LINE__</CODE> are useful in generating an error
  10. message to report an inconsistency detected by the program; the message
  11. can state the source line at which the inconsistency was detected. For
  12. example,
  13. <PRE>fprintf (stderr, &quot;Internal error: &quot;
  14. &quot;negative string length &quot;
  15. &quot;%d at %s, line %d.&quot;,
  16. length, __FILE__, __LINE__);
  17. </PRE>
  18. An <CODE>#include</CODE> directive changes the expansions of <CODE>__FILE__</CODE>
  19. and <CODE>__LINE__</CODE> to correspond to the included file. At the end of
  20. that file, when processing resumes on the input file that contained
  21. the <CODE>#include</CODE> directive, the expansions of <CODE>__FILE__</CODE> and
  22. <CODE>__LINE__</CODE> revert to the values they had before the
  23. <CODE>#include</CODE> (but <CODE>__LINE__</CODE> is then incremented by one as
  24. processing moves to the line after the <CODE>#include</CODE>).
  25. <BR><BR>
  26. A <CODE>#line</CODE> directive changes <CODE>__LINE__</CODE>, and may change
  27. <CODE>__FILE__</CODE> as well. See <A HREF="$$LINK(SEC41)">Line Control</A>.
  28. <BR><BR>
  29. C99 introduces <CODE>__func__</CODE>, and GCC has provided <CODE>__FUNCTION__</CODE>
  30. for a long time. Both of these are strings containing the name of the
  31. current function (there are slight semantic differences; see <A HREF="$$INFOLINK(gnuexts/SEC102)">Function Names as Strings</A>).
  32. Neither of them is a macro; the preprocessor does not know the
  33. name of the current function. They tend to be useful in conjunction
  34. with <CODE>__FILE__</CODE> and <CODE>__LINE__</CODE>, though.