Lines Matching full:array

99 #define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))  argument
104 * @brief Zero if @p array has an array type, a compile error otherwise
108 #define IS_ARRAY(array) \
110 !__builtin_types_compatible_p(__typeof__(array), \
111 __typeof__(&(array)[0])))
114 * @brief Number of elements in the given @p array
116 * In C++, due to language limitations, this will accept as @p array
120 * In C, passing a pointer as @p array causes a compile error.
122 #define ARRAY_SIZE(array) \
123 ((size_t) (IS_ARRAY(array) + (sizeof(array) / sizeof((array)[0]))))
128 * @brief Whether @p ptr is an element of @p array
131 * in that it also ensures that @p ptr is aligned to an array-element boundary
132 * of @p array.
134 * In C, passing a pointer as @p array causes a compile error.
136 * @param array the array in question
139 * @return 1 if @p ptr is part of @p array, 0 otherwise
141 #define IS_ARRAY_ELEMENT(array, ptr) \ argument
142 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
143 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]) && \
144 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) % sizeof((array)[0]) == 0)
147 * @brief Index of @p ptr within @p array
150 * when @p ptr does not fall into the range of @p array or when @p ptr
151 * is not aligned to an array-element boundary of @p array.
153 * In C, passing a pointer as @p array causes a compile error.
155 * @param array the array in question
156 * @param ptr pointer to an element of @p array
158 * @return the array index of @p ptr within @p array, on success
160 #define ARRAY_INDEX(array, ptr) \ argument
162 __ASSERT_NO_MSG(IS_ARRAY_ELEMENT(array, ptr)); \
163 (__typeof__((array)[0]) *)(ptr) - (array); \
167 * @brief Check if a pointer @p ptr lies within @p array.
169 * In C but not C++, this causes a compile error if @p array is not an array
170 * (e.g. if @p ptr and @p array are mixed up).
172 * @param array an array
174 * @return 1 if @p ptr is part of @p array, 0 otherwise
176 #define PART_OF_ARRAY(array, ptr) \ argument
177 ((ptr) && POINTER_TO_UINT(array) <= POINTER_TO_UINT(ptr) && \
178 POINTER_TO_UINT(ptr) < POINTER_TO_UINT(&(array)[ARRAY_SIZE(array)]))
181 * @brief Array-index of @p ptr within @p array, rounded down
184 * difference that it accepts any @p ptr in the range of @p array rather than
185 * exclusively a @p ptr aligned to an array-element boundary of @p array.
188 * when @p ptr does not fall into the range of @p array.
190 * In C, passing a pointer as @p array causes a compile error.
192 * @param array the array in question
193 * @param ptr pointer to an element of @p array
195 * @return the array index of @p ptr within @p array, on success
197 #define ARRAY_INDEX_FLOOR(array, ptr) \ argument
199 __ASSERT_NO_MSG(PART_OF_ARRAY(array, ptr)); \
200 (POINTER_TO_UINT(ptr) - POINTER_TO_UINT(array)) / sizeof((array)[0]); \
428 * @brief Convert a binary array into string representation.
430 * @param buf The binary array to convert
431 * @param buflen The length of the binary array to convert
440 * @brief Convert a hexadecimal string into a binary array.
447 * @return The length of the binary array, or 0 if an error occurred.