mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-28 09:50:09 +01:00
glib-aux: add NM_CAST_PPTR() macro
This commit is contained in:
parent
457be83839
commit
4efc6f030a
1 changed files with 15 additions and 0 deletions
|
|
@ -683,6 +683,21 @@ NM_G_ERROR_MSG(GError *error)
|
|||
#define NM_STRUCT_OFFSET_ENSURE_TYPE(type, container, field) G_STRUCT_OFFSET(container, field)
|
||||
#endif
|
||||
|
||||
/* Casts (arg) to (type**), but also having a compile time check that
|
||||
* the arg is some sort of pointer to a pointer.
|
||||
*
|
||||
* The only purpose of this macro is some additional compile time safety,
|
||||
* that the argument is a pointer to pointer. But then it will C cast any kind
|
||||
* of such argument. */
|
||||
#define NM_CAST_PPTR(type, arg) \
|
||||
({ \
|
||||
typeof(*(arg)) *const _arg = (arg); \
|
||||
typeof(*_arg) _arg2 = _arg ? *_arg : NULL; \
|
||||
_nm_unused const void *const _arg3 = _arg2; \
|
||||
\
|
||||
(type **) _arg; \
|
||||
})
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
/* these macros cast (value) to
|
||||
* - "const char **" (for "MC", mutable-const)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue