MentOS  0.8.0
The Mentoring Operating System
Macros
array.h File Reference

Go to the source code of this file.

Macros

#define ARRAY_ALLOC   malloc
 Function for allocating memory for the array.
 
#define ARRAY_FREE   free
 Function for freeing the memory for the array.
 
#define DECLARE_ARRAY(type, name)
 Declares a new dynamic-size array structure. More...
 

Detailed Description

Macro Definition Documentation

◆ DECLARE_ARRAY

#define DECLARE_ARRAY (   type,
  name 
)
Value:
typedef struct arr_##name##_t { \
const unsigned size; \
type *buffer; \
} arr_##name##_t; \
arr_##name##_t alloc_arr_##name(unsigned len) \
{ \
arr_##name##_t a = { len, len > 0 ? ARRAY_ALLOC(sizeof(type) * len) : NULL }; \
memset(a.buffer, 0, sizeof(type) * len); \
return a; \
} \
static inline void free_arr_##name(arr_##name##_t *arr) \
{ \
ARRAY_FREE(arr->buffer); \
}
#define ARRAY_ALLOC
Function for allocating memory for the array.
Definition: array.h:15
#define NULL
Define NULL.
Definition: stddef.h:10

Declares a new dynamic-size array structure.