@@ -372,6 +372,21 @@ extern "C" {
372
372
? ((n) - ((d) / 2)) / (d) \
373
373
: ((n) + ((d) / 2)) / (d))
374
374
375
+ /**
376
+ * @cond INTERNAL_HIDDEN
377
+ */
378
+ #define _minmax_unique (op , a , b , ua , ub ) ({ \
379
+ __typeof__(a) ua = (a); \
380
+ __typeof__(b) ub = (b); \
381
+ op(ua, ub); \
382
+ })
383
+
384
+ #define _minmax_cnt (op , a , b , cnt ) \
385
+ _minmax_unique(op, a, b, UTIL_CAT(_value_a_, cnt), UTIL_CAT(_value_b_, cnt))
386
+ /**
387
+ * @endcond
388
+ */
389
+
375
390
#ifndef MAX
376
391
/**
377
392
* @brief Obtain the maximum of two values.
@@ -397,12 +412,7 @@ extern "C" {
397
412
* - to generate constant integer, e.g. __aligned(max(4,5))
398
413
* - static variable, e.g. array like static uint8_t array[max(...)];
399
414
*/
400
- #define max (a , b ) ({ \
401
- /* random suffix to avoid naming conflict */ \
402
- __typeof__ (a ) _value_a_ = (a ); \
403
- __typeof__ (b ) _value_b_ = (b ); \
404
- (_value_a_ > _value_b_ ) ? _value_a_ : _value_b_ ; \
405
- })
415
+ #define max (a , b ) _minmax_cnt(MAX, a, b, __COUNTER__)
406
416
#endif
407
417
408
418
#ifndef MIN
@@ -426,12 +436,7 @@ extern "C" {
426
436
* Macro ensures that expressions are evaluated only once. See @ref max for
427
437
* macro limitations.
428
438
*/
429
- #define min (a , b ) ({ \
430
- /* random suffix to avoid naming conflict */ \
431
- __typeof__ (a ) _value_a_ = (a ); \
432
- __typeof__ (b ) _value_b_ = (b ); \
433
- (_value_a_ < _value_b_ ) ? _value_a_ : _value_b_ ; \
434
- })
439
+ #define min (a , b ) _minmax_cnt(MIN, a, b, __COUNTER__)
435
440
#endif
436
441
437
442
#ifndef MAX_FROM_LIST
0 commit comments