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: --------------------------------------------------

| Hare type | C type | C header | |===========|==============|=====================| | bool | _Bool, bool | stdbool.h (C99-C17) | |-----------|--------------|---------------------| | int | (signed) int | - | |-----------|--------------|---------------------| | size | size_t | stddef.h | |-----------|--------------|---------------------| | uint | unsigned int | - | |-----------|--------------|---------------------| | uintptr | uintptr_t | stdint.h | |-----------|--------------|---------------------| | valist | va_list | stdarg.h | --------------------------------------------------

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

| Hare type | C type | Differences | |===========|===================|==============================================| | void | void | Hare's void is a zero-size type; C's void is | | | | an incomplete opaque type. This distinction | | | | isn't relevant for C interop. In both | | | | languages, void pointers are used as generic | | | | pointers. | |-----------|-------------------|----------------------------------------------| | f32 | float _Imaginary | The types are equivalent in representation, | | f64 | double _Imaginary | but behavior differs when casting between | | [2]f32 | float _Complex | real, imaginary, and complex types. | | [2]f64 | double _Complex | | --------------------------------------------------------------------------------

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

Index

Types

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

Functions

fn fromstr(const str) *char;
fn fromstr_buf(const str, []char) *char;
fn strlen(*const char) size;
fn tostr(*const char) (const str | utf8::invalid);
fn tostr_unsafe(*const char) const str;

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.

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 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.