📄 type-encoding.html
字号:
<html lang="en">
<head>
<title>Using the GNU Compiler Collection (GCC)</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="Using the GNU Compiler Collection (GCC)">
<meta name="generator" content="makeinfo 4.3">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home">
<!--
Copyright © 1988, 1989, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
1999, 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
<p>Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.2 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "GNU General Public License" and "Funding
Free Software", the Front-Cover texts being (a) (see below), and with
the Back-Cover Texts being (b) (see below). A copy of the license is
included in the section entitled "GNU Free Documentation License".
<p>(a) The FSF's Front-Cover Text is:
<p>A GNU Manual
<p>(b) The FSF's Back-Cover Text is:
<p>You have freedom to copy and modify this GNU Manual, like GNU
software. Copies published by the Free Software Foundation raise
funds for GNU development.-->
</head>
<body>
<div class="node">
<p>
Node:<a name="Type%20encoding">Type encoding</a>,
Next:<a rel="next" accesskey="n" href="Garbage-Collection.html#Garbage%20Collection">Garbage Collection</a>,
Previous:<a rel="previous" accesskey="p" href="Executing-code-before-main.html#Executing%20code%20before%20main">Executing code before main</a>,
Up:<a rel="up" accesskey="u" href="Objective-C.html#Objective-C">Objective-C</a>
<hr><br>
</div>
<h3 class="section">Type encoding</h3>
<p>The Objective-C compiler generates type encodings for all the
types. These type encodings are used at runtime to find out information
about selectors and methods and about objects and classes.
<p>The types are encoded in the following way:
<p><table><tr align="left"><td valign="top"><code>char</code>
</td><td valign="top"><code>c</code>
<br></td></tr><tr align="left"><td valign="top"><code>unsigned char</code>
</td><td valign="top"><code>C</code>
<br></td></tr><tr align="left"><td valign="top"><code>short</code>
</td><td valign="top"><code>s</code>
<br></td></tr><tr align="left"><td valign="top"><code>unsigned short</code>
</td><td valign="top"><code>S</code>
<br></td></tr><tr align="left"><td valign="top"><code>int</code>
</td><td valign="top"><code>i</code>
<br></td></tr><tr align="left"><td valign="top"><code>unsigned int</code>
</td><td valign="top"><code>I</code>
<br></td></tr><tr align="left"><td valign="top"><code>long</code>
</td><td valign="top"><code>l</code>
<br></td></tr><tr align="left"><td valign="top"><code>unsigned long</code>
</td><td valign="top"><code>L</code>
<br></td></tr><tr align="left"><td valign="top"><code>long long</code>
</td><td valign="top"><code>q</code>
<br></td></tr><tr align="left"><td valign="top"><code>unsigned long long</code>
</td><td valign="top"><code>Q</code>
<br></td></tr><tr align="left"><td valign="top"><code>float</code>
</td><td valign="top"><code>f</code>
<br></td></tr><tr align="left"><td valign="top"><code>double</code>
</td><td valign="top"><code>d</code>
<br></td></tr><tr align="left"><td valign="top"><code>void</code>
</td><td valign="top"><code>v</code>
<br></td></tr><tr align="left"><td valign="top"><code>id</code>
</td><td valign="top"><code>@</code>
<br></td></tr><tr align="left"><td valign="top"><code>Class</code>
</td><td valign="top"><code>#</code>
<br></td></tr><tr align="left"><td valign="top"><code>SEL</code>
</td><td valign="top"><code>:</code>
<br></td></tr><tr align="left"><td valign="top"><code>char*</code>
</td><td valign="top"><code>*</code>
<br></td></tr><tr align="left"><td valign="top">unknown type
</td><td valign="top"><code>?</code>
<br></td></tr><tr align="left"><td valign="top">bit-fields
</td><td valign="top"><code>b</code> followed by the starting position of the bit-field, the type of the bit-field and the size of the bit-field (the bit-fields encoding was changed from the NeXT's compiler encoding, see below)
<br></td></tr></table>
<p>The encoding of bit-fields has changed to allow bit-fields to be properly
handled by the runtime functions that compute sizes and alignments of
types that contain bit-fields. The previous encoding contained only the
size of the bit-field. Using only this information it is not possible to
reliably compute the size occupied by the bit-field. This is very
important in the presence of the Boehm's garbage collector because the
objects are allocated using the typed memory facility available in this
collector. The typed memory allocation requires information about where
the pointers are located inside the object.
<p>The position in the bit-field is the position, counting in bits, of the
bit closest to the beginning of the structure.
<p>The non-atomic types are encoded as follows:
<p><table><tr align="left"><td valign="top">pointers
</td><td valign="top"><code>^</code> followed by the pointed type.
<br></td></tr><tr align="left"><td valign="top">arrays
</td><td valign="top"><code>[</code> followed by the number of elements in the array followed by the type of the elements followed by <code>]</code>
<br></td></tr><tr align="left"><td valign="top">structures
</td><td valign="top"><code>{</code> followed by the name of the structure (or <code>?</code> if the structure is unnamed), the <code>=</code> sign, the type of the members and by <code>}</code>
<br></td></tr><tr align="left"><td valign="top">unions
</td><td valign="top"><code>(</code> followed by the name of the structure (or <code>?</code> if the union is unnamed), the <code>=</code> sign, the type of the members followed by <code>)</code>
<br></td></tr></table>
<p>Here are some types and their encodings, as they are generated by the
compiler on an i386 machine:
<br><p>
<p><table><tr align="left"><td valign="top">Objective-C type
</td><td valign="top">Compiler encoding
<br></td></tr><tr align="left"><td valign="top">
<pre class="example"> int a[10];
</pre>
</td><td valign="top"><code>[10i]</code>
<br></td></tr><tr align="left"><td valign="top">
<pre class="example"> struct {
int i;
float f[3];
int a:3;
int b:2;
char c;
}
</pre>
</td><td valign="top"><code>{?=i[3f]b128i3b131i2c}</code>
<br></td></tr></table>
<br><p>
<p>In addition to the types the compiler also encodes the type
specifiers. The table below describes the encoding of the current
Objective-C type specifiers:
<br><p>
<p><table><tr align="left"><td valign="top">Specifier
</td><td valign="top">Encoding
<br></td></tr><tr align="left"><td valign="top"><code>const</code>
</td><td valign="top"><code>r</code>
<br></td></tr><tr align="left"><td valign="top"><code>in</code>
</td><td valign="top"><code>n</code>
<br></td></tr><tr align="left"><td valign="top"><code>inout</code>
</td><td valign="top"><code>N</code>
<br></td></tr><tr align="left"><td valign="top"><code>out</code>
</td><td valign="top"><code>o</code>
<br></td></tr><tr align="left"><td valign="top"><code>bycopy</code>
</td><td valign="top"><code>O</code>
<br></td></tr><tr align="left"><td valign="top"><code>oneway</code>
</td><td valign="top"><code>V</code>
<br></td></tr></table>
<br><p>
<p>The type specifiers are encoded just before the type. Unlike types
however, the type specifiers are only encoded when they appear in method
argument types.
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -