Made casting more explicit for better compatibility with different compilers (#41)

This commit is contained in:
johan0A 2024-10-12 02:25:22 +02:00 committed by GitHub
parent 4ce3105f58
commit 05eb12bed7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

8
clay.h
View File

@ -481,11 +481,11 @@ typedef struct
Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) { Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
uint64_t totalSizeBytes = capacity * sizeof(Clay_String); uint64_t totalSizeBytes = capacity * sizeof(Clay_String);
Clay__WarningArray array = CLAY__INIT(Clay__WarningArray){.capacity = capacity, .length = 0}; Clay__WarningArray array = CLAY__INIT(Clay__WarningArray){.capacity = capacity, .length = 0};
uint64_t nextAllocAddress = (uint64_t)(arena->nextAllocation + arena->memory); uint64_t nextAllocAddress = (uint64_t)arena->nextAllocation + (uint64_t)arena->memory;
uint64_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String))); uint64_t arenaOffsetAligned = nextAllocAddress + (CLAY__ALIGNMENT(Clay_String) - (nextAllocAddress % CLAY__ALIGNMENT(Clay_String)));
arenaOffsetAligned -= (uint64_t)arena->memory; arenaOffsetAligned -= (uint64_t)arena->memory;
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) { if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
array.internalArray = (Clay__Warning*)(arena->memory + arenaOffsetAligned); array.internalArray = (Clay__Warning*)((uint64_t)arena->memory + (uint64_t)arenaOffsetAligned);
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes; arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
} }
else { else {
@ -515,12 +515,12 @@ Clay__Warning *Clay__WarningArray_Add(Clay__WarningArray *array, Clay__Warning i
void* Clay__Array_Allocate_Arena(uint32_t capacity, uint32_t itemSize, uint32_t alignment, Clay_Arena *arena) void* Clay__Array_Allocate_Arena(uint32_t capacity, uint32_t itemSize, uint32_t alignment, Clay_Arena *arena)
{ {
uint64_t totalSizeBytes = capacity * itemSize; uint64_t totalSizeBytes = capacity * itemSize;
uint64_t nextAllocAddress = (uint64_t)(arena->nextAllocation + arena->memory); uint64_t nextAllocAddress = (uint64_t)arena->nextAllocation + (uint64_t)arena->memory;
uint64_t arenaOffsetAligned = nextAllocAddress + (alignment - (nextAllocAddress % alignment)); uint64_t arenaOffsetAligned = nextAllocAddress + (alignment - (nextAllocAddress % alignment));
arenaOffsetAligned -= (uint64_t)arena->memory; arenaOffsetAligned -= (uint64_t)arena->memory;
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) { if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes; arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
return (void*)(arena->memory + arenaOffsetAligned); return (void*)((uint64_t)arena->memory + (uint64_t)arenaOffsetAligned);
} }
else { else {
if (Clay__warningsEnabled) { if (Clay__warningsEnabled) {