Gears-C/src/util.h

28 lines
748 B
C

#pragma once
#include <assert.h>
#define DEFAULT_ALIGNMENT (2*sizeof(rawptr))
#define Len(x) ((sizeof(x)/sizeof(0[x])) / ((size_t)(!(sizeof(x) % sizeof(0[x])))))
#define MakeString(x) #x
#define BitEq(var, bits) (((var) & (bits)) == bits)
#define AlignPow2(x, b) (((x) + (b) - 1) & (~((b) - 1)))
#define IsPow2(x) ((x) != 0 && ((x) &((x) - 1)) == 0)
// String Functions
u32 StrLen(const char *str);
b32 StrEq(const char *l, const char *r);
i32 SPrintf(char *buf, rawptr fmt, ...);
// Memory Functions
void MemZero(void *ptr, isize size);
// Math Functions
u32 u32Min(u32 l, u32 r);
i32 i32Min(i32 l, i32 r);
u32 u32Max(u32 l, u32 r);
i32 i32Max(i32 l, i32 r);
i32 i32Clamp(i32 v, i32 min, i32 max);
u32 u32Clamp(u32 v, u32 min, u32 max);