J
Jordan Abel
Was wondering what people think of this header file:
#ifdef MALLOC_H
#define MALLOC_H
# ifdef __cplusplus
# include <cstdlib>
struct voidptr_ {
void *x;
template <typename T> inline operator T * () {
return ((T *) x);
}
};
static inline voidptr_ malloc_(size_t n)
{
return (voidptr_) {
malloc(n)
};
}
# define malloc(x) malloc_(x)
template<typename T> static inline void free(T *x) {
free((void *)x);
}
template<typename T> static inline T *realloc(T *x, size_t n) {
return (T *)realloc((void*)x,n);
}
# else /* C */
# include <stdlib.h>
# ifdef __GNUC__
# define realloc(p,s) ((__typeof__(p))(realloc(p,s)))
# endif /* GNU C */
# endif /* C++/C */
#define tcalloc(n,T) ((T*)(calloc(n,sizeof(T))))
#endif /* incl guard */
#ifdef MALLOC_H
#define MALLOC_H
# ifdef __cplusplus
# include <cstdlib>
struct voidptr_ {
void *x;
template <typename T> inline operator T * () {
return ((T *) x);
}
};
static inline voidptr_ malloc_(size_t n)
{
return (voidptr_) {
malloc(n)
};
}
# define malloc(x) malloc_(x)
template<typename T> static inline void free(T *x) {
free((void *)x);
}
template<typename T> static inline T *realloc(T *x, size_t n) {
return (T *)realloc((void*)x,n);
}
# else /* C */
# include <stdlib.h>
# ifdef __GNUC__
# define realloc(p,s) ((__typeof__(p))(realloc(p,s)))
# endif /* GNU C */
# endif /* C++/C */
#define tcalloc(n,T) ((T*)(calloc(n,sizeof(T))))
#endif /* incl guard */