diff options
Diffstat (limited to 'devdocs/gcc~13/method-signatures.html')
| -rw-r--r-- | devdocs/gcc~13/method-signatures.html | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/devdocs/gcc~13/method-signatures.html b/devdocs/gcc~13/method-signatures.html new file mode 100644 index 00000000..f9041538 --- /dev/null +++ b/devdocs/gcc~13/method-signatures.html @@ -0,0 +1,9 @@ +<div class="subsection-level-extent" id="Method-signatures"> <div class="nav-panel"> <p> Previous: <a href="_0040encode" accesskey="p" rel="prev"><code class="code">@encode</code></a>, Up: <a href="type-encoding" accesskey="u" rel="up">Type Encoding</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="subsection" id="Method-Signatures"><span>8.3.3 Method Signatures<a class="copiable-link" href="#Method-Signatures"> ¶</a></span></h1> <p>This section documents the encoding of method types, which is rarely needed to use Objective-C. You should skip it at a first reading; the runtime provides functions that will work on methods and can walk through the list of parameters and interpret them for you. These functions are part of the public “API” and are the preferred way to interact with method signatures from user code. </p> <p>But if you need to debug a problem with method signatures and need to know how they are implemented (i.e., the “ABI”), read on. </p> <p>Methods have their “signature” encoded and made available to the runtime. The “signature” encodes all the information required to dynamically build invocations of the method at runtime: return type and arguments. </p> <p>The “signature” is a null-terminated string, composed of the following: </p> <ul class="itemize mark-bullet"> <li>The return type, including type qualifiers. For example, a method returning <code class="code">int</code> would have <code class="code">i</code> here. </li> +<li>The total size (in bytes) required to pass all the parameters. This includes the two hidden parameters (the object <code class="code">self</code> and the method selector <code class="code">_cmd</code>). </li> +<li>Each argument, with the type encoding, followed by the offset (in bytes) of the argument in the list of parameters. </li> +</ul> <p>For example, a method with no arguments and returning <code class="code">int</code> would have the signature <code class="code">i8@0:4</code> if the size of a pointer is 4. The signature is interpreted as follows: the <code class="code">i</code> is the return type (an <code class="code">int</code>), the <code class="code">8</code> is the total size of the parameters in bytes (two pointers each of size 4), the <code class="code">@0</code> is the first parameter (an object at byte offset <code class="code">0</code>) and <code class="code">:4</code> is the second parameter (a <code class="code">SEL</code> at byte offset <code class="code">4</code>). </p> <p>You can easily find more examples by running the “strings” program on an Objective-C object file compiled by GCC. You’ll see a lot of strings that look very much like <code class="code">i8@0:4</code>. They are signatures of Objective-C methods. </p> </div> <div class="nav-panel"> <p> Previous: <a href="_0040encode"><code class="code">@encode</code></a>, Up: <a href="type-encoding">Type Encoding</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"> + © 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/Method-signatures.html" class="_attribution-link">https://gcc.gnu.org/onlinedocs/gcc-13.1.0/gcc/Method-signatures.html</a> + </p> +</div> |
