types::c+x86_64 +linux

types::c provides type aliases that are compatible with standard C builtin types and typedefs, as specified ISO/IEC 9899 and POSIX, as well as convenience functions for working with C types. This module is useful for C interop, for instance if an external function returns a long or a ssize, or if you need to convert between a C string and a Hare string. The types provided here shouldn't be used for most Hare code.

Some C types aren't provided by this module, since they are provided by the Hare language itself:

Some C types are mostly compatible with Hare types, with minor differences:

Hare doesn't support bit-precise integer types (_BitInt) or decimal floating point types (_Decimal32, _Decimal64, _Decimal128). Hare also doesn't provide any floating point type larger than 8 bytes, implicating `long double` on some platforms.

Additional low-level or implementation-specific types may be defined in rt::.

Index

Types

type char = schar;
type char16 = uint_least16;
type char32 = uint_least32;
type char8 = uchar;
type int_fast16 = i16;
type int_fast32 = i32;
type int_fast64 = i64;
type int_fast8 = i8;
type int_least16 = i16;
type int_least32 = i32;
type int_least64 = i64;
type int_least8 = i8;
type intmax = i64;
type intptr = i64;
type long = i64;
type longlong = i64;
type ptrdiff = i64;
type schar = i8;
type short = i16;
type ssize = i64;
type uchar = u8;
type uint_fast16 = u16;
type uint_fast32 = u32;
type uint_fast64 = u64;
type uint_fast8 = u8;
type uint_least16 = u16;
type uint_least32 = u32;
type uint_least64 = u64;
type uint_least8 = u8;
type uintmax = u64;
type ulong = u64;
type ulonglong = u64;
type ushort = u16;
type wchar = i32;
type wint = u32;

Constants

def CHAR16_MAX: char16 = UINT_LEAST16_MAX;
def CHAR16_MIN: char16 = UINT_LEAST16_MIN;
def CHAR32_MAX: char32 = UINT_LEAST32_MAX;
def CHAR32_MIN: char32 = UINT_LEAST32_MIN;
def CHAR8_MAX: char8 = UCHAR_MAX;
def CHAR8_MIN: char8 = UCHAR_MIN;
def CHAR_MAX: char = SCHAR_MAX;
def CHAR_MIN: char = SCHAR_MIN;
def INTMAX_MAX: intmax = types::I64_MAX;
def INTMAX_MIN: intmax = types::I64_MIN;
def INTPTR_MAX: intptr = types::I64_MAX;
def INTPTR_MIN: intptr = types::I64_MIN;
def INT_FAST16_MAX: int_fast16 = types::I16_MAX;
def INT_FAST16_MIN: int_fast16 = types::I16_MIN;
def INT_FAST32_MAX: int_fast32 = types::I32_MAX;
def INT_FAST32_MIN: int_fast32 = types::I32_MIN;
def INT_FAST64_MAX: int_fast64 = types::I64_MAX;
def INT_FAST64_MIN: int_fast64 = types::I64_MIN;
def INT_FAST8_MAX: int_fast8 = types::I8_MAX;
def INT_FAST8_MIN: int_fast8 = types::I8_MIN;
def INT_LEAST16_MAX: int_least16 = types::I16_MAX;
def INT_LEAST16_MIN: int_least16 = types::I16_MIN;
def INT_LEAST32_MAX: int_least32 = types::I32_MAX;
def INT_LEAST32_MIN: int_least32 = types::I32_MIN;
def INT_LEAST64_MAX: int_least64 = types::I64_MAX;
def INT_LEAST64_MIN: int_least64 = types::I64_MIN;
def INT_LEAST8_MAX: int_least8 = types::I8_MAX;
def INT_LEAST8_MIN: int_least8 = types::I8_MIN;
def LLONG_MAX: longlong = types::I64_MAX;
def LLONG_MIN: longlong = types::I64_MIN;
def LONG_MAX: long = types::I64_MAX;
def LONG_MIN: long = types::I64_MIN;
def PTRDIFF_MAX: ptrdiff = types::I64_MAX;
def PTRDIFF_MIN: ptrdiff = types::I64_MIN;
def SCHAR_MAX: schar = types::I8_MAX;
def SCHAR_MIN: schar = types::I8_MIN;
def SHORT_MAX: short = types::I16_MAX;
def SHORT_MIN: short = types::I16_MIN;
def SSIZE_MAX: ssize = types::I64_MAX;
def SSIZE_MIN: ssize = types::I64_MIN;
def UCHAR_MAX: uchar = types::U8_MAX;
def UCHAR_MIN: uchar = types::U8_MIN;
def UINTMAX_MAX: uintmax = types::U64_MAX;
def UINTMAX_MIN: uintmax = types::U64_MIN;
def UINT_FAST16_MAX: uint_fast16 = types::U16_MAX;
def UINT_FAST16_MIN: uint_fast16 = types::U16_MIN;
def UINT_FAST32_MAX: uint_fast32 = types::U32_MAX;
def UINT_FAST32_MIN: uint_fast32 = types::U32_MIN;
def UINT_FAST64_MAX: uint_fast64 = types::U64_MAX;
def UINT_FAST64_MIN: uint_fast64 = types::U64_MIN;
def UINT_FAST8_MAX: uint_fast8 = types::U8_MAX;
def UINT_FAST8_MIN: uint_fast8 = types::U8_MIN;
def UINT_LEAST16_MAX: uint_least16 = types::U16_MAX;
def UINT_LEAST16_MIN: uint_least16 = types::U16_MIN;
def UINT_LEAST32_MAX: uint_least32 = types::U32_MAX;
def UINT_LEAST32_MIN: uint_least32 = types::U32_MIN;
def UINT_LEAST64_MAX: uint_least64 = types::U64_MAX;
def UINT_LEAST64_MIN: uint_least64 = types::U64_MIN;
def UINT_LEAST8_MAX: uint_least8 = types::U8_MAX;
def UINT_LEAST8_MIN: uint_least8 = types::U8_MIN;
def ULLONG_MAX: ulonglong = types::U64_MAX;
def ULLONG_MIN: ulonglong = types::U64_MIN;
def ULONG_MAX: ulong = types::U64_MAX;
def ULONG_MIN: ulong = types::U64_MIN;
def USHRT_MAX: ushort = types::U16_MAX;
def USHRT_MIN: ushort = types::U16_MIN;
def WCHAR_MAX: wchar = types::I32_MAX;
def WCHAR_MIN: wchar = types::I32_MIN;
def WINT_MAX: wint = types::U32_MAX;
def WINT_MIN: wint = types::U32_MIN;

Globals

let empty_string: *const char;

Functions

fn fromstr(s: const str) *char;
fn fromstr_buf(s: const str, sl: []char) *char;
fn nulstr(s: const str) *const char;
fn strlen(cstr: *const char) size;
fn tostr(cstr: *const char) (const str | utf8::invalid);
fn tostr_unsafe(cstr: *const char) const str;
fn tostrn(cstr: *const char, length: size) (const str | utf8::invalid);
fn tostrn_unsafe(cstr: *const char, length: size) const str;
fn unterminatedstr(s: const str) *const char;

Types

type char[link]

type char = schar;

Integer type compatible with `char`, as specified by ISO/IEC 9899.

type char16[link]

type char16 = uint_least16;

Integer type compatible with `char16_t`, as defined in <uchar.h> and specified by ISO/IEC 9899:2011.

type char32[link]

type char32 = uint_least32;

Integer type compatible with `char32_t`, as defined in <uchar.h> and specified by ISO/IEC 9899:2011.

type char8[link]

type char8 = uchar;

Integer type compatible with `char8_t`, as defined in <uchar.h> and specified by ISO/IEC 9899:2023.

type int_fast16[link]

type int_fast16 = i16;

Integer type compatible with `int_fast16_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_fast32[link]

type int_fast32 = i32;

Integer type compatible with `int_fast32_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_fast64[link]

type int_fast64 = i64;

Integer type compatible with `int_fast64_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_fast8[link]

type int_fast8 = i8;

Integer type compatible with `int_fast8_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_least16[link]

type int_least16 = i16;

Integer type compatible with `int_least16_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_least32[link]

type int_least32 = i32;

Integer type compatible with `int_least32_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_least64[link]

type int_least64 = i64;

Integer type compatible with `int_least64_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type int_least8[link]

type int_least8 = i8;

Integer type compatible with `int_least8_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type intmax[link]

type intmax = i64;

Integer type compatible with `intmax_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

Note that this type isn't necessarily the actual maximum integer type. This type should only be used when required for C interop.

type intptr[link]

type intptr = i64;

Integer type compatible with `intptr_t`, as defined in <stdint.h> and specified by ISO/IEC 9899.

type long[link]

type long = i64;

Integer type compatible with `signed long`, as specified by ISO/IEC 9899.

type longlong[link]

type longlong = i64;

Integer type compatible with `signed long long`, as specified by ISO/IEC 9899:1999.

type ptrdiff[link]

type ptrdiff = i64;

Integer type compatible with `ptrdiff_t`, as defined in <stddef.h> and specified by ISO/IEC 9899.

type schar[link]

type schar = i8;

Integer type compatible with `signed char`, as specified by ISO/IEC 9899.

type short[link]

type short = i16;

Integer type compatible with `signed short`, as specified by ISO/IEC 9899.

type ssize[link]

type ssize = i64;

Integer type compatible with `ssize_t`, as defined in <sys/types.h> and specified by POSIX.

type uchar[link]

type uchar = u8;

Integer type compatible with `unsigned char`, as specified by ISO/IEC 9899.

type uint_fast16[link]

type uint_fast16 = u16;

Integer type compatible with `uint_fast16_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_fast32[link]

type uint_fast32 = u32;

Integer type compatible with `uint_fast32_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_fast64[link]

type uint_fast64 = u64;

Integer type compatible with `uint_fast64_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_fast8[link]

type uint_fast8 = u8;

Integer type compatible with `uint_fast8_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_least16[link]

type uint_least16 = u16;

Integer type compatible with `uint_least16_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_least32[link]

type uint_least32 = u32;

Integer type compatible with `uint_least32_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_least64[link]

type uint_least64 = u64;

Integer type compatible with `uint_least64_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uint_least8[link]

type uint_least8 = u8;

Integer type compatible with `uint_least8_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

type uintmax[link]

type uintmax = u64;

Integer type compatible with `uintmax_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1999.

Note that this type isn't necessarily the actual maximum integer type. This type should only be used when required for C interop.

type ulong[link]

type ulong = u64;

Integer type compatible with `unsigned long`, as specified by ISO/IEC 9899.

type ulonglong[link]

type ulonglong = u64;

Integer type compatible with `unsigned long long`, as specified by ISO/IEC 9899:1999.

type ushort[link]

type ushort = u16;

Integer type compatible with `unsigned short`, as specified by ISO/IEC 9899.

type wchar[link]

type wchar = i32;

Integer type compatible with `wchar_t`, as defined in <stddef.h> and specified by ISO/IEC 9899.

type wint[link]

type wint = u32;

Integer type compatible with `wint_t`, as defined in <stdint.h> and specified by ISO/IEC 9899:1994.

Constants

def CHAR16_MAX[link]

def CHAR16_MAX: char16 = UINT_LEAST16_MAX;

Maximum value which can be stored in a char16 type.

def CHAR16_MIN[link]

def CHAR16_MIN: char16 = UINT_LEAST16_MIN;

Minimum value which can be stored in a char16 type.

def CHAR32_MAX[link]

def CHAR32_MAX: char32 = UINT_LEAST32_MAX;

Maximum value which can be stored in a char32 type.

def CHAR32_MIN[link]

def CHAR32_MIN: char32 = UINT_LEAST32_MIN;

Minimum value which can be stored in a char32 type.

def CHAR8_MAX[link]

def CHAR8_MAX: char8 = UCHAR_MAX;

Maximum value which can be stored in a char8 type.

def CHAR8_MIN[link]

def CHAR8_MIN: char8 = UCHAR_MIN;

Minimum value which can be stored in a char8 type.

def CHAR_MAX[link]

def CHAR_MAX: char = SCHAR_MAX;

Maximum value which can be stored in a char type.

def CHAR_MIN[link]

def CHAR_MIN: char = SCHAR_MIN;

Minimum value which can be stored in a char type.

def INTMAX_MAX[link]

def INTMAX_MAX: intmax = types::I64_MAX;

Maximum value which can be stored in an intmax type.

def INTMAX_MIN[link]

def INTMAX_MIN: intmax = types::I64_MIN;

Minimum value which can be stored in an intmax type.

def INTPTR_MAX[link]

def INTPTR_MAX: intptr = types::I64_MAX;

Maximum value which can be stored in an intptr type.

def INTPTR_MIN[link]

def INTPTR_MIN: intptr = types::I64_MIN;

Minimum value which can be stored in an intptr type.

def INT_FAST16_MAX[link]

def INT_FAST16_MAX: int_fast16 = types::I16_MAX;

Maximum value which can be stored in an int_fast16 type.

def INT_FAST16_MIN[link]

def INT_FAST16_MIN: int_fast16 = types::I16_MIN;

Minimum value which can be stored in an int_fast16 type.

def INT_FAST32_MAX[link]

def INT_FAST32_MAX: int_fast32 = types::I32_MAX;

Maximum value which can be stored in an int_fast32 type.

def INT_FAST32_MIN[link]

def INT_FAST32_MIN: int_fast32 = types::I32_MIN;

Minimum value which can be stored in an int_fast32 type.

def INT_FAST64_MAX[link]

def INT_FAST64_MAX: int_fast64 = types::I64_MAX;

Maximum value which can be stored in an int_fast64 type.

def INT_FAST64_MIN[link]

def INT_FAST64_MIN: int_fast64 = types::I64_MIN;

Minimum value which can be stored in an int_fast64 type.

def INT_FAST8_MAX[link]

def INT_FAST8_MAX: int_fast8 = types::I8_MAX;

Maximum value which can be stored in an int_fast8 type.

def INT_FAST8_MIN[link]

def INT_FAST8_MIN: int_fast8 = types::I8_MIN;

Minimum value which can be stored in an int_fast8 type.

def INT_LEAST16_MAX[link]

def INT_LEAST16_MAX: int_least16 = types::I16_MAX;

Maximum value which can be stored in an int_least16 type.

def INT_LEAST16_MIN[link]

def INT_LEAST16_MIN: int_least16 = types::I16_MIN;

Minimum value which can be stored in an int_least16 type.

def INT_LEAST32_MAX[link]

def INT_LEAST32_MAX: int_least32 = types::I32_MAX;

Maximum value which can be stored in an int_least32 type.

def INT_LEAST32_MIN[link]

def INT_LEAST32_MIN: int_least32 = types::I32_MIN;

Minimum value which can be stored in an int_least32 type.

def INT_LEAST64_MAX[link]

def INT_LEAST64_MAX: int_least64 = types::I64_MAX;

Maximum value which can be stored in an int_least64 type.

def INT_LEAST64_MIN[link]

def INT_LEAST64_MIN: int_least64 = types::I64_MIN;

Minimum value which can be stored in an int_least64 type.

def INT_LEAST8_MAX[link]

def INT_LEAST8_MAX: int_least8 = types::I8_MAX;

Maximum value which can be stored in an int_least8 type.

def INT_LEAST8_MIN[link]

def INT_LEAST8_MIN: int_least8 = types::I8_MIN;

Minimum value which can be stored in an int_least8 type.

def LLONG_MAX[link]

def LLONG_MAX: longlong = types::I64_MAX;

Maximum value which can be stored in a longlong type.

def LLONG_MIN[link]

def LLONG_MIN: longlong = types::I64_MIN;

Minimum value which can be stored in a longlong type.

def LONG_MAX[link]

def LONG_MAX: long = types::I64_MAX;

Maximum value which can be stored in a long type.

def LONG_MIN[link]

def LONG_MIN: long = types::I64_MIN;

Minimum value which can be stored in a long type.

def PTRDIFF_MAX[link]

def PTRDIFF_MAX: ptrdiff = types::I64_MAX;

Maximum value which can be stored in a ptrdiff type.

def PTRDIFF_MIN[link]

def PTRDIFF_MIN: ptrdiff = types::I64_MIN;

Minimum value which can be stored in a ptrdiff type.

def SCHAR_MAX[link]

def SCHAR_MAX: schar = types::I8_MAX;

Maximum value which can be stored in an schar type.

def SCHAR_MIN[link]

def SCHAR_MIN: schar = types::I8_MIN;

Minimum value which can be stored in an schar type.

def SHORT_MAX[link]

def SHORT_MAX: short = types::I16_MAX;

Maximum value which can be stored in a short type.

def SHORT_MIN[link]

def SHORT_MIN: short = types::I16_MIN;

Minimum value which can be stored in a short type.

def SSIZE_MAX[link]

def SSIZE_MAX: ssize = types::I64_MAX;

Maximum value which can be stored in an ssize type.

def SSIZE_MIN[link]

def SSIZE_MIN: ssize = types::I64_MIN;

Minimum value which can be stored in an ssize type.

def UCHAR_MAX[link]

def UCHAR_MAX: uchar = types::U8_MAX;

Maximum value which can be stored in a uchar type.

def UCHAR_MIN[link]

def UCHAR_MIN: uchar = types::U8_MIN;

Minimum value which can be stored in a uchar type.

def UINTMAX_MAX[link]

def UINTMAX_MAX: uintmax = types::U64_MAX;

Maximum value which can be stored in a uintmax type.

def UINTMAX_MIN[link]

def UINTMAX_MIN: uintmax = types::U64_MIN;

Minimum value which can be stored in a uintmax type.

def UINT_FAST16_MAX[link]

def UINT_FAST16_MAX: uint_fast16 = types::U16_MAX;

Maximum value which can be stored in a uint_fast16 type.

def UINT_FAST16_MIN[link]

def UINT_FAST16_MIN: uint_fast16 = types::U16_MIN;

Minimum value which can be stored in a uint_fast16 type.

def UINT_FAST32_MAX[link]

def UINT_FAST32_MAX: uint_fast32 = types::U32_MAX;

Maximum value which can be stored in a uint_fast32 type.

def UINT_FAST32_MIN[link]

def UINT_FAST32_MIN: uint_fast32 = types::U32_MIN;

Minimum value which can be stored in a uint_fast32 type.

def UINT_FAST64_MAX[link]

def UINT_FAST64_MAX: uint_fast64 = types::U64_MAX;

Maximum value which can be stored in a uint_fast64 type.

def UINT_FAST64_MIN[link]

def UINT_FAST64_MIN: uint_fast64 = types::U64_MIN;

Minimum value which can be stored in a uint_fast64 type.

def UINT_FAST8_MAX[link]

def UINT_FAST8_MAX: uint_fast8 = types::U8_MAX;

Maximum value which can be stored in a uint_fast8 type.

def UINT_FAST8_MIN[link]

def UINT_FAST8_MIN: uint_fast8 = types::U8_MIN;

Minimum value which can be stored in a uint_fast8 type.

def UINT_LEAST16_MAX[link]

def UINT_LEAST16_MAX: uint_least16 = types::U16_MAX;

Maximum value which can be stored in a uint_least16 type.

def UINT_LEAST16_MIN[link]

def UINT_LEAST16_MIN: uint_least16 = types::U16_MIN;

Minimum value which can be stored in a uint_least16 type.

def UINT_LEAST32_MAX[link]

def UINT_LEAST32_MAX: uint_least32 = types::U32_MAX;

Maximum value which can be stored in a uint_least32 type.

def UINT_LEAST32_MIN[link]

def UINT_LEAST32_MIN: uint_least32 = types::U32_MIN;

Minimum value which can be stored in a uint_least32 type.

def UINT_LEAST64_MAX[link]

def UINT_LEAST64_MAX: uint_least64 = types::U64_MAX;

Maximum value which can be stored in a uint_least64 type.

def UINT_LEAST64_MIN[link]

def UINT_LEAST64_MIN: uint_least64 = types::U64_MIN;

Minimum value which can be stored in a uint_least64 type.

def UINT_LEAST8_MAX[link]

def UINT_LEAST8_MAX: uint_least8 = types::U8_MAX;

Maximum value which can be stored in a uint_least8 type.

def UINT_LEAST8_MIN[link]

def UINT_LEAST8_MIN: uint_least8 = types::U8_MIN;

Minimum value which can be stored in a uint_least8 type.

def ULLONG_MAX[link]

def ULLONG_MAX: ulonglong = types::U64_MAX;

Maximum value which can be stored in a ulonglong type.

def ULLONG_MIN[link]

def ULLONG_MIN: ulonglong = types::U64_MIN;

Minimum value which can be stored in a ulonglong type.

def ULONG_MAX[link]

def ULONG_MAX: ulong = types::U64_MAX;

Maximum value which can be stored in a ulong type.

def ULONG_MIN[link]

def ULONG_MIN: ulong = types::U64_MIN;

Minimum value which can be stored in a ulong type.

def USHRT_MAX[link]

def USHRT_MAX: ushort = types::U16_MAX;

Maximum value which can be stored in a ushort type.

def USHRT_MIN[link]

def USHRT_MIN: ushort = types::U16_MIN;

Minimum value which can be stored in a ushort type.

def WCHAR_MAX[link]

def WCHAR_MAX: wchar = types::I32_MAX;

Maximum value which can be stored in a wchar type.

def WCHAR_MIN[link]

def WCHAR_MIN: wchar = types::I32_MIN;

Minimum value which can be stored in a wchar type.

def WINT_MAX[link]

def WINT_MAX: wint = types::U32_MAX;

Maximum value which can be stored in a wint type.

def WINT_MIN[link]

def WINT_MIN: wint = types::U32_MIN;

Minimum value which can be stored in a wint type.

Globals

let empty_string[link]

let empty_string: *const char;

An empty NUL-terminated C string.

Functions

fn fromstr[link]

fn fromstr(s: const str) *char;

Converts a Hare string to a C string. The result is allocated; the caller must free it when they're done.

fn fromstr_buf[link]

fn fromstr_buf(s: const str, sl: []char) *char;

Converts a Hare string to a C string. The result is stored into a user-supplied buffer.

fn nulstr[link]

fn nulstr(s: const str) *const char;

Converts a NUL-terminated Hare string to a C string. Aborts if the input string isn't NUL-terminated. The result is borrowed from the input.

fn strlen[link]

fn strlen(cstr: *const char) size;

Computes the length of a NUL-terminated C string, in octets, in O(n). The computed length does not include the NUL terminator.

fn tostr[link]

fn tostr(cstr: *const char) (const str | utf8::invalid);

Converts a C string to a Hare string in O(n). If the string is not valid UTF-8, return encoding::utf8::invalid.

fn tostr_unsafe[link]

fn tostr_unsafe(cstr: *const char) const str;

Converts a C string to a Hare string in O(n), and does not check if it's valid UTF-8.

fn tostrn[link]

fn tostrn(cstr: *const char, length: size) (const str | utf8::invalid);

Converts a C string with a given length to a Hare string. If the string is not valid UTF-8, return encoding::utf8::invalid.

fn tostrn_unsafe[link]

fn tostrn_unsafe(cstr: *const char, length: size) const str;

Converts a C string with a given length to a Hare string, and does not check if it's valid UTF-8.

fn unterminatedstr[link]

fn unterminatedstr(s: const str) *const char;

Converts a non-NUL-terminated Hare string to a *const char. The return value is borrowed from the input, except in the case of an empty string, in which case it is statically allocated.

Use with caution!