This section describes the pre-defined designator classes for fundamental C numeric types. On page 10 we saw that none of these designator types are instantiable: a number on one side of the interface is converted to a number on the other side with the same value.
There are some additional details to note about integer representations. Because Dylan's integer representations do not match C's exactly, for each of the C integer types there are three designator classes that can be used to translate Dylan representations to that C integer. The categories are plain, unsafe, and raw integers.
Plain integer designators -- of which the class <C-unsigned-short> is an example -- translate C integer values to instances of <integer>. If the integer being translated is too big for the destination, the C-FFI signals an error. There are two ways this can happen.
<C-unsigned-short>, and the Dylan value is negative, or if unsigned short on that platform is 16 bits wide, but the Dylan integer has more than 16 significant bits. The check will be omitted if the compiler can determine that no Dylan value outside the safe range can reach there. This can be done using a limited integer type.
<integer>.
<integer> depends on the particular platform, but it is guaranteed to be at least 30 bits in length.
The C-FFI never signals an error for the unsafe designator classes -- of which the class <C-unsafe-unsigned-short> is an example -- but if the destination is too small for the value, the most significant bits of the value are chopped off to fit into the destination. Because there is no checking, using the unsafe designator classes brings a very small performance improvement, but nonetheless you should not use them unless you are certain you will not lose any bits.
Raw designator classes -- of which the class <C-raw-unsigned-int> is an example -- represent the integer on the Dylan side as a <machine-word>. An instance of <machine-word> is guaranteed to have enough bits to represent any C long value, or any C void * value. Note that a <machine-word> value may still have more significant bits than some C integer types, and so the C-FFI may still signal an overflow error if the <machine-word> value, interpreted as indicated by the designator, has more significant bits than may be held in the indicated C type.
Table 1.1 shows all raw, plain, and unsafe integer designator types exported from the C-FFI module.
For each of the fundamental integer designator types, <C-xxx>, there is also a type designating pointers to that type called <C-xxx*>. In addition, the C-FFI defines methods for pointer-value and pointer-value-setter, with appropriate translation behavior for each of the types designating pointers to the fundamental integer designator types.