mirror of
https://github.com/JakeHillion/drgn.git
synced 2024-12-22 01:03:07 +00:00
libdrgn: factor is_array() macro out of array_size()
It'll be used for another macro in the next commit. Signed-off-by: Omar Sandoval <osandov@osandov.com>
This commit is contained in:
parent
630d55aaaf
commit
ea93f5743d
@ -25,11 +25,10 @@
|
|||||||
*
|
*
|
||||||
* @hideinitializer
|
* @hideinitializer
|
||||||
*/
|
*/
|
||||||
#define array_size(arr) \
|
#define array_size(arr) \
|
||||||
static_assert_expression( \
|
static_assert_expression(is_array(arr), \
|
||||||
!types_compatible((arr), &(arr)[0]), "not an array", \
|
"not an array", \
|
||||||
sizeof(arr) / sizeof((arr)[0]) \
|
sizeof(arr) / sizeof((arr)[0]))
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Iterate over every element in an array.
|
* Iterate over every element in an array.
|
||||||
|
@ -68,6 +68,9 @@
|
|||||||
/** Return whether two types or expressions have compatible types. */
|
/** Return whether two types or expressions have compatible types. */
|
||||||
#define types_compatible(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
#define types_compatible(a, b) __builtin_types_compatible_p(typeof(a), typeof(b))
|
||||||
|
|
||||||
|
/** Return whether an expression is an array. */
|
||||||
|
#define is_array(x) (!types_compatible(x, &(x)[0]))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* `static_assert(assert_expression, message)` as an expression that evaluates
|
* `static_assert(assert_expression, message)` as an expression that evaluates
|
||||||
* to `eval_expression`.
|
* to `eval_expression`.
|
||||||
|
Loading…
Reference in New Issue
Block a user