summaryrefslogtreecommitdiff
path: root/devdocs/gcc~13/function-names.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/gcc~13/function-names.html
new repository
Diffstat (limited to 'devdocs/gcc~13/function-names.html')
-rw-r--r--devdocs/gcc~13/function-names.html27
1 files changed, 27 insertions, 0 deletions
diff --git a/devdocs/gcc~13/function-names.html b/devdocs/gcc~13/function-names.html
new file mode 100644
index 00000000..56b88107
--- /dev/null
+++ b/devdocs/gcc~13/function-names.html
@@ -0,0 +1,27 @@
+<div class="section-level-extent" id="Function-Names"> <div class="nav-panel"> <p> Next: <a href="return-address" accesskey="n" rel="next">Getting the Return or Frame Address of a Function</a>, Previous: <a href="incomplete-enums" accesskey="p" rel="prev">Incomplete <code class="code">enum</code> Types</a>, Up: <a href="c-extensions" accesskey="u" rel="up">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div> <h1 class="section" id="Function-Names-as-Strings"><span>6.50 Function Names as Strings<a class="copiable-link" href="#Function-Names-as-Strings"> ΒΆ</a></span></h1> <p>GCC provides three magic constants that hold the name of the current function as a string. In C++11 and later modes, all three are treated as constant expressions and can be used in <code class="code">constexpr</code> constexts. The first of these constants is <code class="code">__func__</code>, which is part of the C99 standard: </p> <p>The identifier <code class="code">__func__</code> is implicitly declared by the translator as if, immediately following the opening brace of each function definition, the declaration </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">static const char __func__[] = "function-name";</pre>
+</div> <p>appeared, where function-name is the name of the lexically-enclosing function. This name is the unadorned name of the function. As an extension, at file (or, in C++, namespace scope), <code class="code">__func__</code> evaluates to the empty string. </p> <p><code class="code">__FUNCTION__</code> is another name for <code class="code">__func__</code>, provided for backward compatibility with old versions of GCC. </p> <p>In C, <code class="code">__PRETTY_FUNCTION__</code> is yet another name for <code class="code">__func__</code>, except that at file scope (or, in C++, namespace scope), it evaluates to the string <code class="code">"top level"</code>. In addition, in C++, <code class="code">__PRETTY_FUNCTION__</code> contains the signature of the function as well as its bare name. For example, this program: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">extern "C" int printf (const char *, ...);
+
+class a {
+ public:
+ void sub (int i)
+ {
+ printf ("__FUNCTION__ = %s\n", __FUNCTION__);
+ printf ("__PRETTY_FUNCTION__ = %s\n", __PRETTY_FUNCTION__);
+ }
+};
+
+int
+main (void)
+{
+ a ax;
+ ax.sub (0);
+ return 0;
+}</pre>
+</div> <p>gives this output: </p> <div class="example smallexample"> <pre class="example-preformatted" data-language="cpp">__FUNCTION__ = sub
+__PRETTY_FUNCTION__ = void a::sub(int)</pre>
+</div> <p>These identifiers are variables, not preprocessor macros, and may not be used to initialize <code class="code">char</code> arrays or be concatenated with string literals. </p> </div> <div class="nav-panel"> <p> Next: <a href="return-address">Getting the Return or Frame Address of a Function</a>, Previous: <a href="incomplete-enums">Incomplete <code class="code">enum</code> Types</a>, Up: <a href="c-extensions">Extensions to the C Language Family</a> [<a href="index#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="indices" title="Index" rel="index">Index</a>]</p> </div><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Free Software Foundation<br>Licensed under the GNU Free Documentation License, Version 1.3.<br>
+ <a href="https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Function-Names.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Function-Names.html</a>
+ </p>
+</div>