Skip to content

Commit

Permalink
Made casting more explicit for better compatibility with different co…
Browse files Browse the repository at this point in the history
…mpilers (#41)
  • Loading branch information
johan0A authored Oct 12, 2024
1 parent 4ce3105 commit 05eb12b
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions clay.h
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,11 @@ typedef struct
Clay__WarningArray Clay__WarningArray_Allocate_Arena(uint32_t capacity, Clay_Arena *arena) {
uint64_t totalSizeBytes = capacity * sizeof(Clay_String);
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)));
arenaOffsetAligned -= (uint64_t)arena->memory;
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;
}
else {
Expand Down Expand Up @@ -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)
{
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));
arenaOffsetAligned -= (uint64_t)arena->memory;
if (arenaOffsetAligned + totalSizeBytes <= arena->capacity) {
arena->nextAllocation = arenaOffsetAligned + totalSizeBytes;
return (void*)(arena->memory + arenaOffsetAligned);
return (void*)((uint64_t)arena->memory + (uint64_t)arenaOffsetAligned);
}
else {
if (Clay__warningsEnabled) {
Expand Down

0 comments on commit 05eb12b

Please sign in to comment.