Commit 22acfb79 by Niels Möller Committed by Martin v. Löwis

* extend.texi (Function Names): Document types of function names.

From-SVN: r29938
parent 7f22ec2e
Wed Oct 13 09:25:03 1999 Niels Mller <nisse@lysator.liu.se>
* extend.texi (Function Names): Document types of function names.
Wed Oct 13 00:45:04 1999 Bernd Schmidt <bernds@cygnus.co.uk> Wed Oct 13 00:45:04 1999 Bernd Schmidt <bernds@cygnus.co.uk>
* reload1.c (reload_reg_free_for_value_p): RELOAD_OTHER reloads with * reload1.c (reload_reg_free_for_value_p): RELOAD_OTHER reloads with
......
...@@ -2999,10 +2999,11 @@ This extension is not supported by GNU C++. ...@@ -2999,10 +2999,11 @@ This extension is not supported by GNU C++.
@node Function Names @node Function Names
@section Function Names as Strings @section Function Names as Strings
GNU CC predefines two string variables to be the name of the current function. GNU CC predefines two magic identifiers to hold the name of the current
The variable @code{__FUNCTION__} is the name of the function as it appears function. The identifier @code{__FUNCTION__} holds the name of the function
in the source. The variable @code{__PRETTY_FUNCTION__} is the name of as it appears in the source. The identifier @code{__PRETTY_FUNCTION__}
the function pretty printed in a language specific fashion. holds the name of the function pretty printed in a language specific
fashion.
These names are always the same in a C function, but in a C++ function These names are always the same in a C function, but in a C++ function
they may be different. For example, this program: they may be different. For example, this program:
...@@ -3038,11 +3039,43 @@ __FUNCTION__ = sub ...@@ -3038,11 +3039,43 @@ __FUNCTION__ = sub
__PRETTY_FUNCTION__ = int a::sub (int) __PRETTY_FUNCTION__ = int a::sub (int)
@end smallexample @end smallexample
These names are not macros: they are predefined string variables. The compiler automagically replaces the identifiers with a string
For example, @samp{#ifdef __FUNCTION__} does not have any special literal containing the appropriate name. Thus, they are neither
preprocessor macros, like @code{__FILE__} and @code{__LINE__}, nor
variables. This means that they catenate with other string literals, and
that they can be used to initialize char arrays. For example
@smallexample
char here[] = "Function " __FUNCTION__ " in " __FILE__;
@end smallexample
On the other hand, @samp{#ifdef __FUNCTION__} does not have any special
meaning inside a function, since the preprocessor does not do anything meaning inside a function, since the preprocessor does not do anything
special with the identifier @code{__FUNCTION__}. special with the identifier @code{__FUNCTION__}.
GNU CC also supports the magic word @code{__func__}, defined by the
draft standard for C-99:
@display
The identifier @code{__func__} is implicitly declared by the translator
as if, immediately following the opening brace of each function
definition, the declaration
@smallexample
static const char __func__[] = "function-name";
@end smallexample
appeared, where function-name is the name of the lexically-enclosing
function. This name is the unadorned name of the function.
@end display
By this definition, @code{__func__} is a variable, not a string literal.
In particular, @code{__func__} does not catenate with other string
literals.
In @code{C++}, @code{__FUNCTION__} and @code{__PRETTY_FUNCTION__} are
variables, declared in the same way as @code{__func__}.
@node Return Address @node Return Address
@section Getting the Return or Frame Address of a Function @section Getting the Return or Frame Address of a Function
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment