rlib
Convenience library for useful things
Loading...
Searching...
No Matches
rtypes.h File Reference

Foundational type aliases used by every rlib header. More...

#include <rlib/rconfig.h>
#include <rlib/types/rmacros.h>
#include <limits.h>
#include <float.h>
#include <rlib/types/rmemops.h>
#include <rlib/types/rendianness.h>
#include <rlib/types/rbitops.h>

Go to the source code of this file.

Macros

Fixed-width integer limits

The MIN / MAX constants for the rint8 / ruint8 / ... types. The typedefs live in rlib/rconfig.h (chosen per host so the sizes are guaranteed); the constants live here so a single include of rlib/rtypes.h covers both.

#define RINT8_MIN   ((rint8) 0x80)
 Minimum value of rint8.
 
#define RINT8_MAX   ((rint8) 0x7f)
 Maximum value of rint8.
 
#define RUINT8_MAX   ((ruint8) 0xff)
 Maximum value of ruint8.
 
#define RINT16_MIN   ((rint16) 0x8000)
 Minimum value of rint16.
 
#define RINT16_MAX   ((rint16) 0x7fff)
 Maximum value of rint16.
 
#define RUINT16_MAX   ((ruint16) 0xffff)
 Maximum value of ruint16.
 
#define RINT32_MIN   ((rint32) 0x80000000)
 Minimum value of rint32.
 
#define RINT32_MAX   ((rint32) 0x7fffffff)
 Maximum value of rint32.
 
#define RUINT32_MAX   ((ruint32) 0xffffffff)
 Maximum value of ruint32.
 
#define RINT64_MIN   ((rint64) RINT64_CONSTANT(0x8000000000000000))
 Minimum value of rint64.
 
#define RINT64_MAX   RINT64_CONSTANT(0x7fffffffffffffff)
 Maximum value of rint64.
 
#define RUINT64_MAX   RUINT64_CONSTANT(0xffffffffffffffff)
 Maximum value of ruint64.
 
Fixed-width integer printf macros and constants

printf / scanf length modifiers and conversion specifiers for each width, plus literal-suffix helpers and the wide-type limits. These are emitted into rlib/rconfig.h with the host-correct spellings; use them as printf ("value=%" RINT64_FMT "\n", v). The values shown here are illustrative — the real ones are resolved per host at configure time.

#define RINT8_MODIFIER   "hh"
 printf length modifier for rint8 / ruint8.
 
#define RINT8_FMT   "hhi"
 printf conversion for rint8.
 
#define RUINT8_FMT   "hhu"
 printf conversion for ruint8.
 
#define RINT16_MODIFIER   "h"
 printf length modifier for rint16 / ruint16.
 
#define RINT16_FMT   "hi"
 printf conversion for rint16.
 
#define RUINT16_FMT   "hu"
 printf conversion for ruint16.
 
#define RINT32_MODIFIER   ""
 printf length modifier for rint32 / ruint32.
 
#define RINT32_FMT   "i"
 printf conversion for rint32.
 
#define RUINT32_FMT   "u"
 printf conversion for ruint32.
 
#define RINT64_MODIFIER   "ll"
 printf length modifier for rint64 / ruint64.
 
#define RINT64_FMT   "lli"
 printf conversion for rint64.
 
#define RUINT64_FMT   "llu"
 printf conversion for ruint64.
 
#define RINTMAX_MODIFIER   "j"
 printf length modifier for rintmax / ruintmax.
 
#define RINTMAX_FMT   "ji"
 printf conversion for rintmax.
 
#define RUINTMAX_FMT   "ju"
 printf conversion for ruintmax.
 
#define RSIZE_MODIFIER   "z"
 printf length modifier for rsize.
 
#define RSSIZE_MODIFIER   "z"
 printf length modifier for rssize.
 
#define RSIZE_FMT   "zu"
 printf conversion for rsize.
 
#define RSSIZE_FMT   "zi"
 printf conversion for rssize.
 
#define RINTPTR_MODIFIER   "t"
 printf length modifier for rintptr / ruintptr.
 
#define RINTPTR_FMT   "ti"
 printf conversion for rintptr.
 
#define RUINTPTR_FMT   "tu"
 printf conversion for ruintptr.
 
#define RINT64_CONSTANT(val)   val
 Suffix an integer literal as a 64-bit signed (rint64) constant.
 
#define RUINT64_CONSTANT(val)   val
 Suffix an integer literal as a 64-bit unsigned (ruint64) constant.
 
#define RUINTMAX_MAX   ((ruintmax) -1)
 Maximum value of ruintmax.
 
#define RINTMAX_MIN   (-RINTMAX_MAX - 1)
 Minimum value of rintmax.
 
#define RINTMAX_MAX   ((rintmax) (RUINTMAX_MAX >> 1))
 Maximum value of rintmax.
 
#define RSIZE_MAX   ((rsize) -1)
 Maximum value of rsize.
 
#define RSSIZE_MIN   (-RSSIZE_MAX - 1)
 Minimum value of rssize.
 
#define RSSIZE_MAX   ((rssize) (RSIZE_MAX >> 1))
 Maximum value of rssize.
 
Optional subsystems

Defined when the corresponding subsystem was compiled in.

#define RLIB_HAVE_THREADS
 Threads, mutexes and TLS are available.
 
#define RLIB_HAVE_MODULES
 Dynamic module loading is available.
 
#define RLIB_HAVE_SIGNALS
 Signal timers are available.
 
#define RLIB_HAVE_FILES
 File and filesystem APIs are available.
 
#define RLIB_HAVE_SOCKETS
 Socket and networking APIs are available.
 
#define RLIB_HAVE_ALLOCA_H
 <alloca.h> is present on the host.
 
Target architecture

Exactly one is defined, for the architecture being built.

#define R_ARCH_X86
 Targeting 32-bit x86.
 
#define R_ARCH_X86_64
 Targeting 64-bit x86-64.
 
#define R_ARCH_IA64
 Targeting Itanium (IA-64).
 
#define R_ARCH_ARM
 Targeting 32-bit ARM.
 
#define R_ARCH_THUMB
 Targeting ARM Thumb.
 
#define R_ARCH_AARCH64
 Targeting 64-bit ARM (AArch64).
 
#define R_ARCH_SPARC
 Targeting SPARC.
 
#define R_ARCH_XTENSA
 Targeting Xtensa.
 
Target operating system

Defined for the OS being built; R_OS_UNIX also covers the Unix-like family (Linux / BSD / Darwin).

#define R_OS_BARE_METAL
 Targeting a bare-metal / no-OS environment.
 
#define R_OS_WIN32
 Targeting Windows.
 
#define R_OS_UNIX
 Targeting a Unix-like OS.
 
#define R_OS_LINUX
 Targeting Linux.
 
#define R_OS_BSD
 Targeting a BSD.
 
#define R_OS_DARWIN
 Targeting macOS / Darwin.
 
#define R_OS_RTEMS
 Targeting RTEMS.
 
Type sizes (bytes)
#define RLIB_SIZEOF_VOID_P   8
 sizeof(void*) on the host.
 
#define RLIB_SIZEOF_INT   4
 sizeof(int) on the host.
 
#define RLIB_SIZEOF_LONG   8
 sizeof(long) on the host.
 
#define RLIB_SIZEOF_INTMAX   8
 sizeof(rintmax) on the host.
 
#define RLIB_SIZEOF_SIZE_T   8
 sizeof(rsize) on the host.
 
getaddrinfo hint flags

Mirror the platform's AI_* constants for DNS resolution.

#define R_AI_PASSIVE
 Address is intended for bind (passive socket).
 
#define R_AI_CANONNAME
 Request the canonical host name.
 
#define R_AI_NUMERICHOST
 Treat the host string as a numeric address only.
 
#define R_AI_V4MAPPED
 Return IPv4-mapped IPv6 addresses if no IPv6 found.
 
#define R_AI_ALL
 Return both IPv6 and IPv4-mapped addresses.
 
#define R_AI_ADDRCONFIG
 Only return families configured on the host.
 

Typedefs

Boolean type
typedef int rboolean
 Boolean type (typedef'd to int).
 
Fixed-width integer types

Exact-width signed and unsigned integers. The typedefs themselves are emitted into the build-generated rlib/rconfig.h (the host's short / int / long widths are probed at configure time so the sizes are guaranteed); they are documented here, where every caller already includes them via rlib/rtypes.h.

typedef signed char rint8
 Signed 8-bit integer.
 
typedef signed short rint16
 Signed 16-bit integer.
 
typedef signed int rint32
 Signed 32-bit integer.
 
typedef signed long rint64
 Signed 64-bit integer.
 
typedef signed long rintmax
 Widest signed integer the host supports.
 
typedef unsigned char ruint8
 Unsigned 8-bit integer.
 
typedef unsigned short ruint16
 Unsigned 16-bit integer.
 
typedef unsigned int ruint32
 Unsigned 32-bit integer.
 
typedef unsigned long ruint64
 Unsigned 64-bit integer.
 
typedef unsigned long ruintmax
 Widest unsigned integer the host supports.
 
Function-pointer prototypes

Common callback shapes used across rlib's container / iterator APIs. Library users typically don't write these typedefs out - they pass function pointers that match the shape into the call sites that ask for them.

typedef void(* RDestroyNotify) (rpointer ptr)
 Destructor callback: free / release the value at ptr.
 
typedef void(* RFunc) (rpointer data, rpointer user)
 Generic iteration callback over (data, user) pairs.
 
typedef int(* RCmpFunc) (rconstpointer a, rconstpointer b)
 Comparison callback returning <0 / 0 / >0 for a vs b.
 
typedef rboolean(* REqualFunc) (rconstpointer a, rconstpointer b)
 Equality predicate.
 
typedef rsize(* RHashFunc) (rconstpointer key)
 Hash function over an opaque key.
 
typedef void(* RKeyValueFunc) (rpointer key, rpointer value, rpointer user)
 Iteration callback over (key, value, user) triples.
 
typedef void(* RKeyValueConstFunc) (rconstpointer key, rconstpointer value, rpointer user)
 Const-visitor iteration callback over (key, value, user) triples.
 
typedef void(* RStrKeyValueFunc) (const rchar *key, rpointer value, rpointer user)
 Iteration callback over (const char *key, value, user).
 
typedef rboolean(* RFuncReturn) (rpointer data, rpointer user)
 Iteration callback that can short-circuit by returning FALSE.
 
typedef rboolean(* RKeyValueFuncReturn) (rpointer key, rpointer value, rpointer user)
 Key-value iteration callback that can short-circuit.
 
typedef void(* RFuncUniversal) ()
 Type-erased function pointer used as a "any callable" placeholder before downcasting to the actual signature.
 
typedef rpointer(* RFuncUniversalReturn) ()
 Type-erased function pointer that returns an rpointer.
 

Floating-point types and constants

#define RFLOAT_MIN   FLT_MIN
 Smallest positive normalised rfloat.
 
#define RFLOAT_MAX   FLT_MAX
 Largest finite rfloat.
 
#define RDOUBLE_MIN   DBL_MIN
 Smallest positive normalised rdouble.
 
#define RDOUBLE_MAX   DBL_MAX
 Largest finite rdouble.
 
#define RFLOAT_INFINITY   ((rfloat)1e500)
 +infinity as rfloat.
 
#define RFLOAT_NAN   (__nan())
 Quiet NaN as rfloat.
 
#define RDOUBLE_INFINITY   ((rdouble)1e500)
 +infinity as rdouble.
 
#define RDOUBLE_NAN   ((rdouble)RFLOAT_NAN)
 Quiet NaN as rdouble.
 
#define R_E   2.718281828459045235360287471352662497757247093700
 Euler's number, e.
 
#define R_LN2   0.693147180559945309417232121458176568075500134360
 Natural log of 2.
 
#define R_LN10   2.302585092994045684017991454684364207601101488629
 Natural log of 10.
 
#define R_LOG_2_BASE10   0.301029995663981195213738894724493026768189881462
 log_10 of 2.
 
#define R_PI   3.141592653589793238462643383279502884197169399375
 pi.
 
#define R_SQRT2   1.414213562373095048801688724209698078569671875377
 Square root of 2.
 
typedef float rfloat
 Single-precision floating point.
 
typedef double rdouble
 Double-precision floating point.
 

Native-width integer types

Aliases for the C native types whose width depends on the host (char, short, int, long). Use the fixed-width rXX / ruXX names from rlib/rconfig.h when the size needs to be predictable.

#define RCHAR_MIN   CHAR_MIN
 
#define RCHAR_MAX   CHAR_MAX
 
#define RSHORT_MIN   SHRT_MIN
 
#define RSHORT_MAX   SHRT_MAX
 
#define RUSHORT_MAX   USHRT_MAX
 
#define RINT_MIN   INT_MIN
 
#define RINT_MAX   INT_MAX
 
#define RUINT_MAX   UINT_MAX
 
#define RLONG_MIN   LONG_MIN
 
#define RLONG_MAX   LONG_MAX
 
#define RULONG_MAX   ULONG_MAX
 
typedef char rchar
 Default character type (char).
 
typedef short rshort
 Default short type (short).
 
typedef long rlong
 Default long type (long).
 
typedef char rschar
 Explicit-signed char (same as rchar on rlib's targets).
 
typedef short rsshort
 Explicit-signed short.
 
typedef long rslong
 Explicit-signed long.
 
typedef int rsint
 Explicit-signed int.
 
typedef unsigned char ruchar
 Unsigned char.
 
typedef unsigned short rushort
 Unsigned short.
 
typedef unsigned long rulong
 Unsigned long.
 
typedef unsigned int ruint
 Unsigned int.
 

Size and file-offset types

rsize / rssize (unsigned and signed pointer-sized) are typedef'd in rlib/rconfig.h. roffset is a 64-bit signed offset used for file / stream positions, large enough to address past the 32-bit boundary on platforms that need it.

#define ROFFSET_MIN   RINT64_MIN
 Minimum value of roffset.
 
#define ROFFSET_MAX   RINT64_MAX
 Maximum value of roffset.
 
#define ROFFSET_MODIFIER   RINT64_MODIFIER
 printf length modifier for roffset.
 
#define ROFFSET_FMT   RINT64_FMT
 printf format specifier for roffset.
 
#define ROFFSET_CONSTANT(val)   RINT64_CONSTANT(val)
 Suffix a literal as an roffset value.
 
typedef unsigned long rsize
 Unsigned pointer-sized size type (like size_t).
 
typedef signed long rssize
 Signed pointer-sized size type (like ssize_t).
 
typedef rint64 roffset
 64-bit signed file / stream offset.
 

Pointer types

rpointer / rconstpointer alias void * / const void *. The conversion macros cast through rintptr / ruintptr / rsize to silence pedantic warnings about pointer / integer conversions on platforms where the widths happen to mismatch.

rintptr / ruintptr (signed / unsigned integers wide enough to hold a pointer, like intptr_t / uintptr_t) are typedef'd in rlib/rconfig.h.

#define RPOINTER_TO_INT(p)   ((rsint) (rintptr) (p))
 Reinterpret a pointer as an rsint.
 
#define RPOINTER_TO_UINT(p)   ((ruint) (ruintptr) (p))
 Reinterpret a pointer as a ruint.
 
#define RPOINTER_TO_SIZE(p)   ((rsize) (p))
 Reinterpret a pointer as an rsize.
 
#define RINT_TO_POINTER(i)   ((rpointer) (rintptr) (i))
 Reinterpret an rsint as a pointer.
 
#define RUINT_TO_POINTER(u)   ((rpointer) (ruintptr) (u))
 Reinterpret a ruint as a pointer.
 
#define RSIZE_TO_POINTER(s)   ((rpointer) (rsize) (s))
 Reinterpret an rsize as a pointer.
 
typedef signed long rintptr
 Signed integer wide enough to hold a pointer (like intptr_t).
 
typedef unsigned long ruintptr
 Unsigned integer wide enough to hold a pointer (like uintptr_t).
 
typedef void * rpointer
 Generic pointer (alias for void *).
 
typedef const void * rconstpointer
 Generic const pointer (alias for const void *).
 

Clock time

Monotonic timestamps and durations expressed as ruint64 nanoseconds. The sentinel R_CLOCK_TIME_NONE doubles as an "infinite" wait value.

#define R_CLOCK_TIME_NONE   ((RClockTime) -1)
 Sentinel value for "no time" / "invalid time".
 
#define R_CLOCK_TIME_INFINITE   R_CLOCK_TIME_NONE
 Alias for R_CLOCK_TIME_NONE used as a "wait forever" sentinel.
 
typedef ruint64 RClockTime
 Unsigned 64-bit timestamp / duration, in nanoseconds.
 
typedef rint64 RClockTimeDiff
 Signed clock-time difference.
 

I/O handle

Cross-platform OS I/O handle: a Windows HANDLE pointer on Win32, a POSIX int file descriptor everywhere else.

#define R_IO_HANDLE_FMT   "i"
 
#define R_IO_HANDLE_INVALID   -1
 
#define RPOINTER_TO_IO_HANDLE(p)   RPOINTER_TO_INT (p)
 
#define RIO_HANDLE_TO_POINTER(h)   RINT_TO_POINTER (h)
 
typedef int RIOHandle
 

Detailed Description

Foundational type aliases used by every rlib header.

rlib spells its primitive types with an r prefix (rint32, rsize, rchar, rpointer, ...) so callers can grep for the project's surface and so the size-suffixed names map predictably to the bit widths their compilers would otherwise negotiate via stdint.h. The fixed-width rXX / ruXX typedefs live in the build-generated rlib/rconfig.h; the native-width ones (rchar, rshort, ...) live here.