ALLOCATE_* family macros cast to the destination type

They were previously evaluated as an expression of `void *` type.
    This allows a C++ compiler to assign it a variable of the
    destination type.
This commit is contained in:
Raphaël Londeix 2015-12-05 13:13:09 +00:00
parent ce42b89da3
commit ff1af0e4cb

View file

@ -13,11 +13,11 @@
#include <assert.h>
#include <stdbool.h>
#define ALLOCATE_NONZERO(Type, count) malloc((count) * sizeof(Type))
#define ALLOCATE_NONZERO(Type, count) ((Type*)malloc((count) * sizeof(Type)))
#define ALLOCATE(Type, count) calloc(count, sizeof(Type))
#define ALLOCATE(Type, count) ((Type*)calloc(count, sizeof(Type)))
#define REALLOCATE_NONZERO(Type, old, new_count) realloc(old, (new_count) * sizeof(Type))
#define REALLOCATE_NONZERO(Type, old, new_count) ((Type*)realloc(old, (new_count) * sizeof(Type)))
#define ARRAY_LENGTH(array) (sizeof(array)/sizeof((array)[0]))