Browse Source

Shorthand for __VA_ARGS__

Scott Lahteine 4 years ago
parent
commit
dc65788511
4 changed files with 39 additions and 39 deletions
  1. 24
    24
      Marlin/src/core/macros.h
  2. 1
    1
      Marlin/src/core/utility.h
  3. 2
    2
      Marlin/src/inc/Conditionals_post.h
  4. 12
    12
      Marlin/src/lcd/menu/menu.h

+ 24
- 24
Marlin/src/core/macros.h View File

@@ -295,8 +295,8 @@ typedef float feedRate_t;
295 295
 #endif
296 296
 
297 297
 // Use NUM_ARGS(__VA_ARGS__) to get the number of variadic arguments
298
-#define _NUM_ARGS(_0,_24_,_23,_22,_21,_20,_19,_18,_17,_16,_15,_14,_13,_12,_11,_10,_9,_8,_7,_6,_5,_4,_3,_2,_1,N,...) N
299
-#define NUM_ARGS(V...) _NUM_ARGS(0,V,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
298
+#define _NUM_ARGS(_,Z,Y,X,W,V,U,T,S,R,Q,P,O,N,M,L,K,J,I,H,G,F,E,D,C,B,A,OUT,...) OUT
299
+#define NUM_ARGS(V...) _NUM_ARGS(0,V,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0)
300 300
 
301 301
 #ifdef __cplusplus
302 302
 
@@ -322,29 +322,29 @@ typedef float feedRate_t;
322 322
 #else
323 323
 
324 324
   #define MIN_2(a,b)      ((a)<(b)?(a):(b))
325
-  #define MIN_3(a,...)    MIN_2(a,MIN_2(__VA_ARGS__))
326
-  #define MIN_4(a,...)    MIN_2(a,MIN_3(__VA_ARGS__))
327
-  #define MIN_5(a,...)    MIN_2(a,MIN_4(__VA_ARGS__))
328
-  #define MIN_6(a,...)    MIN_2(a,MIN_5(__VA_ARGS__))
329
-  #define MIN_7(a,...)    MIN_2(a,MIN_6(__VA_ARGS__))
330
-  #define MIN_8(a,...)    MIN_2(a,MIN_7(__VA_ARGS__))
331
-  #define MIN_9(a,...)    MIN_2(a,MIN_8(__VA_ARGS__))
332
-  #define MIN_10(a,...)   MIN_2(a,MIN_9(__VA_ARGS__))
333
-  #define __MIN_N(N, ...) MIN_##N(__VA_ARGS__)
334
-  #define _MIN_N(N, ...)  __MIN_N(N,__VA_ARGS__)
335
-  #define _MIN(...)       _MIN_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
325
+  #define MIN_3(a,V...)   MIN_2(a,MIN_2(V))
326
+  #define MIN_4(a,V...)   MIN_2(a,MIN_3(V))
327
+  #define MIN_5(a,V...)   MIN_2(a,MIN_4(V))
328
+  #define MIN_6(a,V...)   MIN_2(a,MIN_5(V))
329
+  #define MIN_7(a,V...)   MIN_2(a,MIN_6(V))
330
+  #define MIN_8(a,V...)   MIN_2(a,MIN_7(V))
331
+  #define MIN_9(a,V...)   MIN_2(a,MIN_8(V))
332
+  #define MIN_10(a,V...)  MIN_2(a,MIN_9(V))
333
+  #define __MIN_N(N,V...) MIN_##N(V)
334
+  #define _MIN_N(N,V...)  __MIN_N(N,V)
335
+  #define _MIN(V...)      _MIN_N(NUM_ARGS(V), V)
336 336
 
337 337
   #define MAX_2(a,b)      ((a)>(b)?(a):(b))
338
-  #define MAX_3(a,...)    MAX_2(a,MAX_2(__VA_ARGS__))
339
-  #define MAX_4(a,...)    MAX_2(a,MAX_3(__VA_ARGS__))
340
-  #define MAX_5(a,...)    MAX_2(a,MAX_4(__VA_ARGS__))
341
-  #define MAX_6(a,...)    MAX_2(a,MAX_5(__VA_ARGS__))
342
-  #define MAX_7(a,...)    MAX_2(a,MAX_6(__VA_ARGS__))
343
-  #define MAX_8(a,...)    MAX_2(a,MAX_7(__VA_ARGS__))
344
-  #define MAX_9(a,...)    MAX_2(a,MAX_8(__VA_ARGS__))
345
-  #define MAX_10(a,...)   MAX_2(a,MAX_9(__VA_ARGS__))
346
-  #define __MAX_N(N, ...) MAX_##N(__VA_ARGS__)
347
-  #define _MAX_N(N, ...)  __MAX_N(N,__VA_ARGS__)
348
-  #define _MAX(...)       _MAX_N(NUM_ARGS(__VA_ARGS__), __VA_ARGS__)
338
+  #define MAX_3(a,V...)   MAX_2(a,MAX_2(V))
339
+  #define MAX_4(a,V...)   MAX_2(a,MAX_3(V))
340
+  #define MAX_5(a,V...)   MAX_2(a,MAX_4(V))
341
+  #define MAX_6(a,V...)   MAX_2(a,MAX_5(V))
342
+  #define MAX_7(a,V...)   MAX_2(a,MAX_6(V))
343
+  #define MAX_8(a,V...)   MAX_2(a,MAX_7(V))
344
+  #define MAX_9(a,V...)   MAX_2(a,MAX_8(V))
345
+  #define MAX_10(a,V...)  MAX_2(a,MAX_9(V))
346
+  #define __MAX_N(N,V...) MAX_##N(V)
347
+  #define _MAX_N(N,V...)  __MAX_N(N,V)
348
+  #define _MAX(V...)      _MAX_N(NUM_ARGS(V), V)
349 349
 
350 350
 #endif

+ 1
- 1
Marlin/src/core/utility.h View File

@@ -59,7 +59,7 @@ public:
59 59
   inline void restore() { ref_ = val_; }
60 60
 };
61 61
 
62
-#define REMEMBER(N,X, ...) const restorer<typeof(X)> restorer_##N(X, ##__VA_ARGS__)
62
+#define REMEMBER(N,X,V...) const restorer<typeof(X)> restorer_##N(X, ##V)
63 63
 #define RESTORE(N) restorer_##N.restore()
64 64
 
65 65
 // Converts from an uint8_t in the range of 0-255 to an uint8_t

+ 2
- 2
Marlin/src/inc/Conditionals_post.h View File

@@ -534,13 +534,13 @@
534 534
 /**
535 535
  * ARRAY_BY_EXTRUDERS based on EXTRUDERS
536 536
  */
537
-#define ARRAY_BY_EXTRUDERS(...) ARRAY_N(EXTRUDERS, __VA_ARGS__)
537
+#define ARRAY_BY_EXTRUDERS(V...) ARRAY_N(EXTRUDERS, V)
538 538
 #define ARRAY_BY_EXTRUDERS1(v1) ARRAY_BY_EXTRUDERS(v1, v1, v1, v1, v1, v1)
539 539
 
540 540
 /**
541 541
  * ARRAY_BY_HOTENDS based on HOTENDS
542 542
  */
543
-#define ARRAY_BY_HOTENDS(...) ARRAY_N(HOTENDS, __VA_ARGS__)
543
+#define ARRAY_BY_HOTENDS(V...) ARRAY_N(HOTENDS, V)
544 544
 #define ARRAY_BY_HOTENDS1(v1) ARRAY_BY_HOTENDS(v1, v1, v1, v1, v1, v1)
545 545
 
546 546
 /**

+ 12
- 12
Marlin/src/lcd/menu/menu.h View File

@@ -306,30 +306,30 @@ class MenuItem_bool {
306 306
  *     MenuItem_int3::action_edit(PSTR(MSG_SPEED), &feedrate_percentage, 10, 999)
307 307
  *
308 308
  */
309
-#define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, ...) do { \
309
+#define _MENU_ITEM_VARIANT_P(TYPE, VARIANT, USE_MULTIPLIER, PLABEL, V...) do { \
310 310
     _skipStatic = false; \
311 311
     if (_menuLineNr == _thisItemNr) { \
312 312
       if (encoderLine == _thisItemNr && ui.use_click()) { \
313 313
         _MENU_ITEM_MULTIPLIER_CHECK(USE_MULTIPLIER); \
314
-        MenuItem_##TYPE ::action ## VARIANT(__VA_ARGS__); \
314
+        MenuItem_##TYPE ::action ## VARIANT(V); \
315 315
         if (screen_changed) return; \
316 316
       } \
317 317
       if (ui.should_draw()) \
318
-        draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ## __VA_ARGS__); \
318
+        draw_menu_item ## VARIANT ## _ ## TYPE(encoderLine == _thisItemNr, _lcdLineNr, PLABEL, ##V); \
319 319
     } \
320 320
   ++_thisItemNr; \
321 321
 }while(0)
322 322
 
323 323
 // Used to print static text with no visible cursor.
324 324
 // Parameters: label [, bool center [, bool invert [, char *value] ] ]
325
-#define STATIC_ITEM_P(PLABEL, ...) do{ \
325
+#define STATIC_ITEM_P(PLABEL, V...) do{ \
326 326
   if (_menuLineNr == _thisItemNr) { \
327 327
     if (_skipStatic && encoderLine <= _thisItemNr) { \
328 328
       ui.encoderPosition += ENCODER_STEPS_PER_MENU_ITEM; \
329 329
       ++encoderLine; \
330 330
     } \
331 331
     if (ui.should_draw()) \
332
-      draw_menu_item_static(_lcdLineNr, PLABEL, ## __VA_ARGS__); \
332
+      draw_menu_item_static(_lcdLineNr, PLABEL, ##V); \
333 333
   } \
334 334
   ++_thisItemNr; \
335 335
 } while(0)
@@ -340,16 +340,16 @@ class MenuItem_bool {
340 340
 
341 341
 #define MENU_ITEM_ADDON_END() } }while(0)
342 342
 
343
-#define STATIC_ITEM(LABEL, ...) STATIC_ITEM_P(PSTR(LABEL), ## __VA_ARGS__)
343
+#define STATIC_ITEM(LABEL, V...) STATIC_ITEM_P(PSTR(LABEL), ##V)
344 344
 
345 345
 #define MENU_BACK(LABEL) MENU_ITEM(back, LABEL)
346 346
 #define MENU_ITEM_DUMMY() do { _thisItemNr++; }while(0)
347
-#define MENU_ITEM_P(TYPE, PLABEL, ...)                       _MENU_ITEM_VARIANT_P(TYPE,      , false, PLABEL,                   ## __VA_ARGS__)
348
-#define MENU_ITEM(TYPE, LABEL, ...)                          _MENU_ITEM_VARIANT_P(TYPE,      , false, PSTR(LABEL),              ## __VA_ARGS__)
349
-#define MENU_ITEM_EDIT(TYPE, LABEL, ...)                     _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
350
-#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...)            _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
351
-#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, ...)          _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
352
-#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, ...) _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ## __VA_ARGS__)
347
+#define MENU_ITEM_P(TYPE, PLABEL, V...)                       _MENU_ITEM_VARIANT_P(TYPE,      , false, PLABEL,                   ##V)
348
+#define MENU_ITEM(TYPE, LABEL, V...)                          _MENU_ITEM_VARIANT_P(TYPE,      , false, PSTR(LABEL),              ##V)
349
+#define MENU_ITEM_EDIT(TYPE, LABEL, V...)                     _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
350
+#define MENU_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...)            _MENU_ITEM_VARIANT_P(TYPE, _edit, false, PSTR(LABEL), PSTR(LABEL), ##V)
351
+#define MENU_MULTIPLIER_ITEM_EDIT(TYPE, LABEL, V...)          _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ##V)
352
+#define MENU_MULTIPLIER_ITEM_EDIT_CALLBACK(TYPE, LABEL, V...) _MENU_ITEM_VARIANT_P(TYPE, _edit,  true, PSTR(LABEL), PSTR(LABEL), ##V)
353 353
 
354 354
 ////////////////////////////////////////////
355 355
 /////////////// Menu Screens ///////////////

Loading…
Cancel
Save