 |
__LINE__ |
This macro expands to the current input line number, in the form of a
decimal integer constant. While we call it a predefined macro, it's
a pretty strange macro, since its "definition" changes with each
new line of source code.
__FILE__
and __LINE__
are useful in generating an error
message to report an inconsistency detected by the program; the message
can state the source line at which the inconsistency was detected. For
example,
fprintf (stderr, "Internal error: "
"negative string length "
"%d at %s, line %d.",
length, __FILE__, __LINE__);
An #include
directive changes the expansions of __FILE__
and __LINE__
to correspond to the included file. At the end of
that file, when processing resumes on the input file that contained
the #include
directive, the expansions of __FILE__
and
__LINE__
revert to the values they had before the
#include
(but __LINE__
is then incremented by one as
processing moves to the line after the #include
).
A #line
directive changes __LINE__
, and may change
__FILE__
as well. See Line Control.
C99 introduces __func__
, and GCC has provided __FUNCTION__
for a long time. Both of these are strings containing the name of the
current function (there are slight semantic differences; see Function Names as Strings).
Neither of them is a macro; the preprocessor does not know the
name of the current function. They tend to be useful in conjunction
with __FILE__
and __LINE__
, though.