mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-25 08:20:08 +01:00
shared: add NM_CONST_MAX() macro
There is:
1) glib's MAX() macro, which evaluates arguments multiple times,
but yields a constant expression, if the arguments are constant.
2) NM's NM_MAX() macro, which evaluates arguments exactly once,
but never yields a constant expression.
3) systemd's MAX() which is like NM_MAX().
Now, it's sensible to use
char buf[MAX (A_CONSTANT, ANOTHER_CONSTANT)];
and this works with glib's variant (1).
However, when we include systemd headers, 1) gets redefined to 3), and
above no longer works. That is because we we don't allow VLA and systemd's
macro gives not a constant expression.
Add NM_CONST_MAX() macro which is like systemd's CONST_MAX(). It can
only operate on constant arguments.
This commit is contained in:
parent
e6cf4213a7
commit
b52d3e2ad3
1 changed files with 8 additions and 0 deletions
|
|
@ -1371,6 +1371,14 @@ nm_strcmp_p (gconstpointer a, gconstpointer b)
|
|||
: _b); \
|
||||
})
|
||||
|
||||
/* evaluates to (void) if _A or _B are not constant or of different types */
|
||||
#define NM_CONST_MAX(_A, _B) \
|
||||
(__builtin_choose_expr (( __builtin_constant_p (_A) \
|
||||
&& __builtin_constant_p (_B) \
|
||||
&& __builtin_types_compatible_p (typeof (_A), typeof (_B))), \
|
||||
((_A) > (_B)) ? (_A) : (_B), \
|
||||
((void) 0)))
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static inline guint
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue