From e99e764e59214e962a317e1eb9118fa5641d0661 Mon Sep 17 00:00:00 2001 From: Alois Klink Date: Fri, 30 Dec 2022 11:24:28 +0000 Subject: include: Add cast_int_to_cmocka_value() macro This macro is used to cast data as an integer to a `CMockaValueData`. For backwards compatibility reasons, this explicitly casts to `uintmax_t`, just like the `cast_to_uintmax_type()` macro. For most compilers, this will supress warnings about passing float/intmax_t to this macro. Reviewed-by: Andreas Schneider --- include/cmocka.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/include/cmocka.h b/include/cmocka.h index 0127df0..d96ea82 100644 --- a/include/cmocka.h +++ b/include/cmocka.h @@ -72,6 +72,19 @@ int __stdcall IsDebuggerPresent(); #define cast_ptr_to_uintmax_type(value) \ cast_to_uintmax_type(cast_to_uintptr_type(value)) +/** + * Perform a cast from an integer to CMockaValueData. + * + * For backwards compatibility reasons, this explicitly casts to `uintmax_t`. + * For most compilers, this will supress warnings about passing float/intmax_t + * to this macro. + */ +#define cast_int_to_cmocka_value(value) \ + (CMockaValueData) \ + { \ + .uint_val = (uintmax_t)(value) \ + } + /* GCC have printf type attribute check. */ #ifdef __GNUC__ #define CMOCKA_PRINTF_ATTRIBUTE(a,b) \ -- cgit v1.1