rlib
Convenience library for useful things
Loading...
Searching...
No Matches
Foundational types

Type aliases (rint32, rsize, rchar, rpointer, ...) every other rlib header builds on. More...

Modules

 Bit operations
 Width-specific bit-twiddling macros: count-leading / trailing zeros, population count, parity, and masked shift / rotate.
 
 Endianness
 Byte-order detection, byte-swapping, host/network conversion and alignment-safe load / store of multi-byte integers.
 
 Portability macros
 Compiler-portability shims and small utility macros used throughout rlib.
 

Files

file  rtypes.h
 Foundational type aliases used by every rlib header.
 

Boolean type

typedef int rboolean
 Boolean type (typedef'd to int).
 

Floating-point types and constants

typedef float rfloat
 Single-precision floating point.
 
typedef double rdouble
 Double-precision floating point.
 
#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.
 

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.

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

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.
 

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.

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

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.

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 *).
 
#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.
 

Clock time

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

typedef ruint64 RClockTime
 Unsigned 64-bit timestamp / duration, in nanoseconds.
 
typedef rint64 RClockTimeDiff
 Signed clock-time difference.
 
#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.
 

I/O handle

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

typedef int RIOHandle
 
#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)
 

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.
 

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.
 

Detailed Description

Type aliases (rint32, rsize, rchar, rpointer, ...) every other rlib header builds on.

Macro Definition Documentation

◆ RCHAR_MAX

#define RCHAR_MAX   CHAR_MAX

Maximum value of rchar.

◆ RCHAR_MIN

#define RCHAR_MIN   CHAR_MIN

Minimum value of rchar.

◆ RINT_MAX

#define RINT_MAX   INT_MAX

Maximum value of rsint.

◆ RINT_MIN

#define RINT_MIN   INT_MIN

Minimum value of rsint.

◆ RLONG_MAX

#define RLONG_MAX   LONG_MAX

Maximum value of rlong.

◆ RLONG_MIN

#define RLONG_MIN   LONG_MIN

Minimum value of rlong.

◆ RSHORT_MAX

#define RSHORT_MAX   SHRT_MAX

Maximum value of rshort.

◆ RSHORT_MIN

#define RSHORT_MIN   SHRT_MIN

Minimum value of rshort.

◆ RUINT_MAX

#define RUINT_MAX   UINT_MAX

Maximum value of ruint.

◆ RULONG_MAX

#define RULONG_MAX   ULONG_MAX

Maximum value of rulong.

◆ RUSHORT_MAX

#define RUSHORT_MAX   USHRT_MAX

Maximum value of rushort.

Typedef Documentation

◆ RFuncUniversal

typedef void(* RFuncUniversal) ()

Type-erased function pointer used as a "any callable" placeholder before downcasting to the actual signature.

Casting between this and a real function-pointer type is well-defined; casting through void * would not be.