Lines Matching full:array

97 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))  argument
102 * @brief Zero if @p array has an array type, a compile error otherwise
106 #define IS_ARRAY(array) \
108 !__builtin_types_compatible_p(__typeof__(array), \
109 __typeof__(&(array)[0])))
112 * @brief Number of elements in the given @p array
114 * In C++, due to language limitations, this will accept as @p array
118 * In C, passing a pointer as @p array causes a compile error.
120 #define ARRAY_SIZE(array) \
121 ((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
126 * @brief Declare a flexible array member.
128 * This macro declares a flexible array member in a struct. The member
149 * @brief Whether @p ptr is an element of @p array
152 * in that it also ensures that @p ptr is aligned to an array-element boundary
153 * of @p array.
155 * In C, passing a pointer as @p array causes a compile error.
157 * @param array the array in question
160 * @return 1 if @p ptr is part of @p array, 0 otherwise
162 #define IS_ARRAY_ELEMENT(array, ptr) \ argument
163 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
164 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]) && \
165 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) % sizeof((array)[0]) == 0)
168 * @brief Index of @p ptr within @p array
171 * when @p ptr does not fall into the range of @p array or when @p ptr
172 * is not aligned to an array-element boundary of @p array.
174 * In C, passing a pointer as @p array causes a compile error.
176 * @param array the array in question
177 * @param ptr pointer to an element of @p array
179 * @return the array index of @p ptr within @p array, on success
181 #define ARRAY_INDEX(array, ptr) \ argument
183 __ASSERT_NO_MSG(IS_ARRAY_ELEMENT(array, ptr)); \
184 (__typeof__((array)[0]) *)(ptr) - (array); \
188 * @brief Check if a pointer @p ptr lies within @p array.
190 * In C but not C++, this causes a compile error if @p array is not an array
191 * (e.g. if @p ptr and @p array are mixed up).
193 * @param array an array
195 * @return 1 if @p ptr is part of @p array, 0 otherwise
197 #define PART_OF_ARRAY(array, ptr) \ argument
198 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
199 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]))
202 * @brief Array-index of @p ptr within @p array, rounded down
205 * difference that it accepts any @p ptr in the range of @p array rather than
206 * exclusively a @p ptr aligned to an array-element boundary of @p array.
209 * when @p ptr does not fall into the range of @p array.
211 * In C, passing a pointer as @p array causes a compile error.
213 * @param array the array in question
214 * @param ptr pointer to an element of @p array
216 * @return the array index of @p ptr within @p array, on success
218 #define ARRAY_INDEX_FLOOR(array, ptr) \ argument
220 __ASSERT_NO_MSG(PART_OF_ARRAY(array, ptr)); \
221 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) / sizeof((array)[0]); \
225 * @brief Iterate over members of an array using an index variable
227 * @param array the array in question
228 * @param idx name of array index variable
230 #define ARRAY_FOR_EACH(array, idx) for (size_t idx = 0; (idx) < ARRAY_SIZE(array); ++(idx)) argument
233 * @brief Iterate over members of an array using a pointer
235 * @param array the array in question
236 * @param ptr pointer to an element of @p array
238 #define ARRAY_FOR_EACH_PTR(array, ptr) \ argument
239 for (__typeof__(*(array)) *ptr = (array); (size_t)((ptr) - (array)) < ARRAY_SIZE(array); \
555 * @brief Convert a binary array into string representation.
557 * @param buf The binary array to convert
558 * @param buflen The length of the binary array to convert
567 * @brief Convert a hexadecimal string into a binary array.
574 * @return The length of the binary array, or 0 if an error occurred.