xrt: Add XRT_STRUCT_INIT define

This helps with code that needs to be compiled with both C and C++.
This commit is contained in:
Jakob Bornecrantz 2022-11-20 20:11:39 +00:00
parent 8c0735feec
commit f0021c359f

View file

@ -146,3 +146,31 @@ typedef intptr_t ssize_t;
* @ingroup xrt_iface
*/
#define container_of(ptr, type, field) (type *)((char *)ptr - offsetof(type, field))
#ifdef XRT_DOXYGEN
/*!
* Very small default init for structs that works in both C and C++. Helps with
* code that needs to be compiled with both C and C++.
*
* @ingroup xrt_iface
*/
// clang-format off
#define XRT_STRUCT_INIT {}
// clang-format on
#elif defined(__cplusplus)
// clang-format off
#define XRT_STRUCT_INIT {}
// clang-format on
#else
// clang-format off
#define XRT_STRUCT_INIT {0}
// clang-format on
#endif