| Type | Aliases | Size | Notes |
|---|---|---|---|
c_int8 |
c_byte |
1 | |
c_uint8 |
c_ubyte |
1 | |
c_int16 |
c_short |
2 | |
c_uint16 |
c_ushort |
2 | |
c_int32 |
c_int |
4 | |
c_uint32 |
c_uint |
4 | |
c_int64 |
c_longlong |
8 | |
c_uint64 |
c_ulonglong |
8 | |
c_long |
platform | 4 on Windows, 8 on Unix 64-bit; BigInt values | |
c_ulong |
platform | mirrors c_long; BigInt values |
|
c_float |
4 | ||
c_double |
8 | ||
c_longdouble |
platform | long double; see below |
|
c_bool |
1 | ||
c_char |
1 | 1-char string (Python bytes); also 0..255 |
|
c_wchar |
2 or 4 | 1-char string; 2 on Windows, 4 on Unix | |
c_char_p |
pointer | char * (NUL-terminated) |
|
c_wchar_p |
pointer | wchar_t * (NUL-terminated wide) |
|
c_void_p |
c_voidp |
pointer | opaque pointer / HANDLE |
c_time_t |
8 | time_t (SIZEOF_TIME_T) |
|
c_size_t |
pointer | pointer-sized unsigned integer | |
c_ssize_t |
pointer | pointer-sized signed integer | |
HRESULT |
4 | c_int32 subclass — auto-raise on OleDLL |
Plus the Win32 types, structures and pointer types of ctypes.wintypes under wintypes.
c_longdouble is the C long double, sized as on the platform:
| Platform | c_longdouble |
Size / alignment |
|---|---|---|
| Windows, macOS ARM64 | c_double itself (as in CPython) |
8 / 8 |
| x86-64 Linux and macOS (80-bit x87) | its own type, _type_ "g" |
16 / 16 |
| Linux ARM64 (IEEE binary128) | its own type, _type_ "g" |
16 / 16 |
| 32-bit x86 Linux (80-bit x87) | its own type, _type_ "g" |
12 / 4 |
Its value is a JS number: as CPython's float, a read rounds the
long double to a double (±Infinity beyond the double range). Where it is
its own type it has no __ctype_be__ / __ctype_le__, as in CPython, so it
cannot be a field of a BigEndianStructure / LittleEndianStructure of the
other byte order. It works in arguments (declared, untyped instances and
variadic arguments, which are not promoted), results, callbacks, pointers,
arrays and fields; calls that use it always go through the generic AOT trampoline.
On macOS x86-64 a union of a long double and an integer field, passed or returned
by value, does not match the C compiler: the System V AMD64 ABI classifier (as in
CPython) passes it in memory, while clang's Darwin ABI uses an integer and an SSE
register. Pass such unions by reference there.
As in CPython, a c_void_p value is an integer address (BigInt, or null
for NULL); a JS string passed to a c_void_p parameter is a wchar_t *
string and a Buffer a char * string. On Windows, c_int and c_long
are distinct classes that are interchangeable as arguments; see
Python ctypes parity.
Builtin scalar types return ordinary JS values. A subclass instead produces an instance containing the original C bytes, without invoking its constructor, public buffer factory or writer. Derived scalar fields, array elements, pointer indexing and callback arguments likewise expose typed instances; memory views remain live, including in mirror mode.
The result pipeline is:
C bytes -> restype representation -> _check_retval_ -> errcheck -> OUT/INOUT.
A static _check_retval_ receives the represented result and can replace it
or throw. It is captured when the function is bound; reassigning an attribute's
restype rebuilds that binding.
class CheckedInt extends c_int32 {
static _check_retval_(value) {
return value.value + 100;
}
}
const checkedAbs = libc.func("abs", CheckedInt, [c_int32]);
checkedAbs(-7); // 107
Explicit HRESULT validation runs before errcheck with all loaders and
prototype callers, not only OleDLL. An error in result checking prevents
both errcheck and output conversion.
OleDLL attributes and func(name) default to HRESULT; other loaders
default to c_int. An explicit restype overrides the default, but an
OleDLL function still raises for a negative result (CPython
FUNCFLAG_HRESULT) unless the restype class has its own _check_retval_,
which replaces the HRESULT check, as in CPython.