---
icon: package
label: c
---

Interop with pointers and C structs.

```python
from typing import overload

def malloc(size: int) -> 'void_p': ...
def free(ptr: 'void_p') -> None: ...
def sizeof(type: str) -> int: ...
def refl(name: str) -> '_refl': ...
def memset(ptr: 'void_p', value: int, size: int) -> None: ...
def memcpy(dst: 'void_p', src: 'void_p', size: int) -> None: ...

class _refl:
    def __call__(self) -> 'struct': ...
    def __getitem__(self, key: str) -> int: ...
    def name(self) -> str: ...
    def size(self) -> int: ...

class void_p:
    def __add__(self, i: int) -> 'void_p': ...
    def __sub__(self, i: int) -> 'void_p': ...
    def __eq__(self, other: 'void_p') -> bool: ...
    def __ne__(self, other: 'void_p') -> bool: ...
    def offset(self, i: int) -> 'void_p': ...

    def hex(self) -> str: ...
    @staticmethod
    def from_hex(s: str) -> 'void_p': ...

    def read_char(self) -> int: ...
    def read_uchar(self) -> int: ...
    def read_short(self) -> int: ...
    def read_ushort(self) -> int: ...
    def read_int(self) -> int: ...
    def read_uint(self) -> int: ...
    def read_long(self) -> int: ...
    def read_ulong(self) -> int: ...
    def read_longlong(self) -> int: ...
    def read_ulonglong(self) -> int: ...
    def read_float(self) -> float: ...
    def read_double(self) -> float: ...
    def read_bool(self) -> bool: ...
    def read_void_p(self) -> 'void_p': ...
    def read_bytes(self, size: int) -> bytes: ...
    def read_struct(self, type: str) -> 'struct': ...

    def write_char(self, value: int) -> None: ...
    def write_uchar(self, value: int) -> None: ...
    def write_short(self, value: int) -> None: ...
    def write_ushort(self, value: int) -> None: ...
    def write_int(self, value: int) -> None: ...
    def write_uint(self, value: int) -> None: ...
    def write_long(self, value: int) -> None: ...
    def write_ulong(self, value: int) -> None: ...
    def write_longlong(self, value: int) -> None: ...
    def write_ulonglong(self, value: int) -> None: ...
    def write_float(self, value: float) -> None: ...
    def write_double(self, value: float) -> None: ...
    def write_bool(self, value: bool) -> None: ...
    def write_void_p(self, value: 'void_p') -> None: ...
    def write_bytes(self, value: bytes) -> None: ...
    def write_struct(self, value: 'struct') -> None: ...

    def get_base_offset(self) -> int: ...
    @overload
    def set_base_offset(self, offset: int) -> None: ...
    @overload
    def set_base_offset(self, offset: str) -> None: ...
    
class struct:
    @overload
    def __init__(self, size: int): ...
    @overload
    def __init__(self, p: 'void_p', size: int): ...
    @overload
    def __init__(self, s: str): ...
    @overload
    def __init__(self, b: bytes): ...

    def addr(self) -> 'void_p': ...
    def copy(self) -> 'struct': ...
    def size(self) -> int: ...
    def __eq__(self, other: 'struct') -> bool: ...
    def __ne__(self, other: 'struct') -> bool: ...

    def to_string(self) -> str: ...
    def to_bytes(self) -> bytes: ...

    def read_char(self, offset=0) -> int: ...
    def read_uchar(self, offset=0) -> int: ...
    def read_short(self, offset=0) -> int: ...
    def read_ushort(self, offset=0) -> int: ...
    def read_int(self, offset=0) -> int: ...
    def read_uint(self, offset=0) -> int: ...
    def read_long(self, offset=0) -> int: ...
    def read_ulong(self, offset=0) -> int: ...
    def read_longlong(self, offset=0) -> int: ...
    def read_ulonglong(self, offset=0) -> int: ...
    def read_float(self, offset=0) -> float: ...
    def read_double(self, offset=0) -> float: ...
    def read_bool(self, offset=0) -> bool: ...
    def read_void_p(self, offset=0) -> 'void_p': ...

    def write_char(self, value: int, offset=0) -> None: ...
    def write_uchar(self, value: int, offset=0) -> None: ...
    def write_short(self, value: int, offset=0) -> None: ...
    def write_ushort(self, value: int, offset=0) -> None: ...
    def write_int(self, value: int, offset=0) -> None: ...
    def write_uint(self, value: int, offset=0) -> None: ...
    def write_long(self, value: int, offset=0) -> None: ...
    def write_ulong(self, value: int, offset=0) -> None: ...
    def write_longlong(self, value: int, offset=0) -> None: ...
    def write_ulonglong(self, value: int, offset=0) -> None: ...
    def write_float(self, value: float, offset=0) -> None: ...
    def write_double(self, value: float, offset=0) -> None: ...
    def write_bool(self, value: bool, offset=0) -> None: ...
    def write_void_p(self, value: 'void_p', offset=0) -> None: ...

char_ = refl("char")
uchar_ = refl("uchar")
short_ = refl("short")
ushort_ = refl("ushort")
int_ = refl("int")
uint_ = refl("uint")
long_ = refl("long")
ulong_ = refl("ulong")
longlong_ = refl("longlong")
ulonglong_ = refl("ulonglong")
float_ = refl("float")
double_ = refl("double")
bool_ = refl("bool")

char_p = void_p
uchar_p = void_p
short_p = void_p
ushort_p = void_p
int_p = void_p
uint_p = void_p
long_p = void_p
ulong_p = void_p
longlong_p = void_p
ulonglong_p = void_p
float_p = void_p
double_p = void_p
bool_p = void_p
```