-
Notifications
You must be signed in to change notification settings - Fork 0
Types
candlerb edited this page May 15, 2011
·
11 revisions
This page contains a canonical list of type symbols recognized by attach_function and Struct#layout
-
:char
– 8-bit character -
:uchar
– 8-bit unsigned character -
:int8
– 8-bit signed integer -
:uint8
– 8-bit unsigned integer -
:short
– 16-bit signed integer -
:ushort
– 16-bit unsigned integer -
:int16
– 16-bit signed integer -
:uint16
– 16-bit unsigned integer -
:int
– 32-bit signed integer -
:uint
– 32-bit unsigned integer -
:int32
– 32-bit signed integer -
:uint32
– 32-bit unsigned integer -
:long
– long int – platform-specific size 1 -
:ulong
– unsigned long int – platform-specific size -
:int64
– 64-bit signed integer -
:uint64
– 64-bit unsigned integer -
:long_long
– 64-bit signed integer -
:ulong_long
– 64-bit unsigned integer -
:float
– 32-bit floating point -
:double
– 64-bit floating point (double-precision) -
:pointer
– pointer – platform-specific size -
:string
– C-style (NULL-terminated) character string. NOTE: If the function modifies the string buffer use:pointer
instead. That is,:string
should be considered to beconst char *
. (In fact, MRI will let you modify a:string
in place, but jruby will not, so this usage is not portable) -
:bool
– (?? 1 byte in C++) -
:size_t
– size_t from stddef.h – platform-dependent size -
:in_addr_t
– 32-bit address in network byte order (FFI >= 1.0.8) -
:in_port_t
– 16-bit port in network byte order (FFI >= 1.0.8) - Enums – You can use an enum group (or its symbol) as a type
For function return type only:
-
:void
– For functions that return nothing (return type void).
For function argument type only:
-
:buffer_in
– Similar to:pointer
, but optimized for Buffers that the function can only read (not write). -
:buffer_out
– Similar to:pointer
, but optimized for Buffers that the function can only write (not read). -
:buffer_inout
– Similar to:pointer
, but may be optimized for Buffers. -
:varargs
– see examples for an example
Apparently there are most types available as well. For a full list see lib/ffi/platform/<your platform>/types.conf
(FFI >= 1.0.8)
1 this thread explains some of the different sizes on 64 versus 32-bit, but you shouldn’t have to worry about it.