mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 01:20:07 +01:00
shared: add _NM_ENSURE_TYPE_CONST()
The sole purpose of this is more type-safe macros. An alternative solution would be to define a function instead of a macro. But if the function is unused (currently!) you get a compiler warning (on some compilers even when marking the function as "static inline", if it's in the source file). A workaround for that would be to mark the function as _nm_unused, or to use a macro instead. _NM_ENSURE_TYPE_CONST() is to aid the macro solution.
This commit is contained in:
parent
8f1b542bd7
commit
17dc6a9da6
1 changed files with 2 additions and 0 deletions
|
|
@ -635,8 +635,10 @@ NM_G_ERROR_MSG (GError *error)
|
|||
* It's useful to check the let the compiler ensure that @value is
|
||||
* of a certain type. */
|
||||
#define _NM_ENSURE_TYPE(type, value) (_Generic ((value), type: (value)))
|
||||
#define _NM_ENSURE_TYPE_CONST(type, value) (_Generic ((value), const type: ((const type) (value)), type: ((const type) (value))))
|
||||
#else
|
||||
#define _NM_ENSURE_TYPE(type, value) (value)
|
||||
#define _NM_ENSURE_TYPE_CONST(type, value) ((const type) (value))
|
||||
#endif
|
||||
|
||||
#if _NM_CC_SUPPORT_GENERIC
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue