Sfoglia il codice sorgente

CE_ALIGNOF x-platform macro implemented

mikymod 12 anni fa
parent
commit
3ae9067bd2
2 ha cambiato i file con 9 aggiunte e 1 eliminazioni
  1. 1 1
      src/core/mem/Allocator.h
  2. 8 0
      src/core/mem/Memory.h

+ 1 - 1
src/core/mem/Allocator.h

@@ -78,7 +78,7 @@ void call_destructor_and_deallocate(Allocator& a, T* ptr)
 /// @note
 /// @a allocator must be a reference to an existing allocator.
 #define CE_NEW(allocator, T)\
-	new ((allocator).allocate(sizeof(T), alignof(T))) T
+	new ((allocator).allocate(sizeof(T), CE_ALIGNOF(T))) T
 
 /// Calls destructor on @a ptr and deallocates memory using the
 /// given @a allocator.

+ 8 - 0
src/core/mem/Memory.h

@@ -75,5 +75,13 @@ inline void dump(void* p, size_t size, size_t word_size)
 	os::printf("\n");
 }
 
+#ifdef _MSC_VER
+	#define CE_ALIGNOF(x) __alignof(x)
+#elif defined __GNUG__
+	#define CE_ALIGNOF(x) __alignof__(x)
+#else
+	#error "Compiler not supported."
+#endif
+
 } // namespace memory
 } // namespace crown