/** * Generic array */ #ifndef LIBDI_INCLUDE_ARRAY_H_ #define LIBDI_INCLUDE_ARRAY_H_ #ifdef __cplusplus extern "C" { #endif #include #define DI_ARRAY_SIZE(array) (sizeof(array) / \ sizeof(array[0])) /** * DI generic array placeholder */ struct di_array { size_t size; /**< Number of elements in array */ void *begin; /**< Begin address of array */ }; /**< Declare array and initialize */ #define DI_ARRAY_DECL(name, ptr, type, size) \ static struct di_array name = { size, &ptr } /**< Get entry pointer at element from array name */ #define di_array_entry(array, element, type) \ &((type *)(array).begin)[element] /**< Loop over array with name, item and type */ #define di_array_foreach(array, iter, type) \ for (type *(iter) = (type *)(array).begin; iter < (((type *)(array).begin) + (array).size); iter++) #ifdef __cplusplus } #endif #endif /* LIBDI_INCLUDE_ARRAY_H_ */