toolchain: Add single arguments evaluation macros for min and max
MAX() and MIN() were evaluating arguments twice. If arguments are functions they were called twice which resulted in bigger code and potential misbehavior. Added alternative macros (Z_MAX, Z_MIN) which can be used instead. Macros have usage limitations thus they are not replacements. They are also relying on GCC extension thus placed in gcc.h Signed-off-by: Krzysztof Chruscinski <krzysztof.chruscinski@nordicsemi.no>
This commit is contained in:
parent
6768148cc5
commit
bea966dea1
2 changed files with 38 additions and 0 deletions
|
@ -89,10 +89,20 @@ constexpr size_t ARRAY_SIZE(T(&)[N]) { return N; }
|
|||
#define INLINE
|
||||
#endif
|
||||
|
||||
/** @brief Return larger value of two provided expressions.
|
||||
*
|
||||
* @note Arguments are evaluated twice. See Z_MAX for GCC only, single
|
||||
* evaluation version.
|
||||
*/
|
||||
#ifndef MAX
|
||||
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
/** @brief Return smaller value of two provided expressions.
|
||||
*
|
||||
* @note Arguments are evaluated twice. See Z_MIN for GCC only, single
|
||||
* evaluation version.
|
||||
*/
|
||||
#ifndef MIN
|
||||
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue