#ifndef BASE_CORE_H #define BASE_CORE_H //- compiler definitions #if defined(_MSC_VER) # define COMPILER_MSVC 1 #elif defined(__clang__) # define COMPILER_CLANG 1 #elif defined(__GNUC__) # define COMPILER_GCC 1 #else # error Unsupported compiler #endif //- architecture definitions #if defined(__arm__) || defined(__aarch64__) #define ARCH_ARM 1 #elif defined(__i386__) || defined(__x86_64__) #define ARCH_x86_64 1 #endif //- compiler definitions //- core stuff /* assert an expression and output the file and the line */ #define internal static #define global_variable static #define local_persist static #define arena_align (2 * sizeof(void *)) #define Min(a, b) (((a) < (b)) ? (a) : (b)) #define Max(a, b) (((a) > (b)) ? (a) : (b)) #define Unused(x) (void)(x) #define Nil 0 #define Deprecated __attribute__((__deprecated__)) //- breakpoints #if ARCH_ARM #define breakpoint() __asm__ volatile("brk #0") #elif ARCH_x86_64 #define breakpoint() __asm__ volatile("int3") #endif #if COMPILER_MSVC #include #define breakpoint() __debugbreak() #endif //- #define MemCpy(dest, src, len) memcpy((dest), (src), (len)) #define MemSet(dest, len) memset((dest), (1), (len)) #define MemSetZero(dest, len) memset((dest), (0), (len)) //- attributes macros #if COMPILER_MSVC #pragma section("read_only", read) #define ReadOnly __declspec(allocate("read_only")) #elif COMPILER_GCC || COMPILER_CLANG #if PLATFORM_APPLE #define ReadOnly __attribute__((section("__TEXT,__const"))) #else // NOTE: adding # to comment out the asmw arning message produced by gcc // https://lkml.iu.edu/hypermail/linux/kernel/0105.2/1108.html #define ReadOnly __attribute__((section(".rodata#"))) #endif // PLATFORM_APPLE #else #define ReadOnly #endif // COMPILER_MSVC //- attributes macros // havving issues with compiler analyzer telling me that my arena allocaters could potentially return a non null value // the solution i found to this problem we're these 2: // https://clang.llvm.org/docs/AttributeReference.html#returns-nonnull // https://gcc.gnu.org/onlinedocs/gcc/Common-Attributes.html#Common-Function-Attributes #if COMPILER_CLANG || COMPILER_GCC #define RETURNS_NON_NULL_VALUE __attribute__((returns_nonnull)) #else #define RETURNS_NON_NULL_VALUE #endif // COMPILER_CLANG || COMPILER_GCC #if COMPILER_GCC || COMPILER_CLANG #define SHOULD_BE_NON_NULL(...) __attribute__((nonnull (__VA_ARGS__))) #else #define SHOULD_BE_NON_NULL(...) #endif // COMPILER_GCC || COMPILER_CLANG //- #if COMPILER_GCC || COMPILER_CLANG #define Assert(x) \ do \ { \ if(!(x)) \ { \ breakpoint(); \ } \ } while(0) #else #define Assert(x) \ do \ { \ if(!(x)) \ { \ breakpoint(); \ } \ } while(0) #endif // COMPILER_GCC //- types typedef uint64_t u64; typedef uint32_t u32; typedef uint16_t u16; typedef uint8_t u8; typedef int8_t s8; typedef int16_t s16; typedef int32_t s32; typedef int64_t s64; typedef float f32; typedef double f64; typedef s32 b32; typedef s16 b16; typedef s8 b8; typedef uintptr_t umm; typedef intptr_t smm; #endif // BASE_CORE_H