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.
The types are encoded in the following way:
@c @sp 1
@multitable @columnfractions .25 .75
@item @code{char}
@tab @code{c}
@item @code{unsigned char}
@tab @code{C}
@item @code{short}
@tab @code{s}
@item @code{unsigned short}
@tab @code{S}
@item @code{int}
@tab @code{i}
@item @code{unsigned int}
@tab @code{I}
@item @code{long}
@tab @code{l}
@item @code{unsigned long}
@tab @code{L}
@item @code{long long}
@tab @code{q}
@item @code{unsigned long long}
@tab @code{Q}
@item @code{float}
@tab @code{f}
@item @code{double}
@tab @code{d}
@item @code{void}
@tab @code{v}
@item @code{id}
@tab @code{@@}
@item @code{Class}
@tab @code{#}
@item @code{SEL}
@tab @code{:}
@item @code{char*}
@tab @code{*}
@item unknown type
@tab @code{?}
@item bitfields
@tab @code{b} followed by the starting position of the bitfield, the type of the bitfield and the size of the bitfield (the bitfields encoding was changed from the NeXT's compiler encoding, see below)
@end multitable
@c @sp 1
The encoding of bitfields has changed to allow bitfields to be properly
handled by the runtime functions that compute sizes and alignments of
types that contain bitfields. The previous encoding contained only the
size of the bitfield. Using only this information it is not possible to
reliably compute the size occupied by the bitfield. 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.
The position in the bitfield is the position, counting in bits, of the
bit closest to the beginning of the structure.
The non-atomic types are encoded as follows:
@c @sp 1
@multitable @columnfractions .2 .8
@item pointers
@tab @code{'^'} followed by the pointed type.
@item arrays
@tab @code{'['} followed by the number of elements in the array followed by the type of the elements followed by @code{']'}
@item structures
@tab @code{'@{'} followed by the name of the structure (or '?' if the structure is unnamed), the '=' sign, the type of the members and by @code{'@}'}
@item unions
@tab @code{'('} followed by the name of the structure (or '?' if the union is unnamed), the '=' sign, the type of the members followed by @code{')'}
@end multitable
Here are some types and their encodings, as they are generated by the
compiler on a i386 machine:
@sp 1
@multitable @columnfractions .25 .75
@item Objective-C type
@tab Compiler encoding
@item
@example
int a[10];
@end example
@tab @code{[10i]}
@item
@example
struct @{
int i;
float f[3];
int a:3;
int b:2;
char c;
@}
@end example
@tab @code{@{?=i[3f]b128i3b131i2c@}}
@end multitable
@sp 1
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:
@sp 1
@multitable @columnfractions .25 .75
@item Specifier
@tab Encoding
@item @code{const}
@tab @code{r}
@item @code{in}
@tab @code{n}
@item @code{inout}
@tab @code{N}
@item @code{out}
@tab @code{o}
@item @code{bycopy}
@tab @code{O}
@item @code{oneway}
@tab @code{V}
@end multitable
@sp 1
The type specifiers are encoded just before the type. Unlike types
however, the type specifiers are only encoded when they appear in method