]> de.git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
Fix warning, and better tests for __VA_ARGS__
authorDale Weiler <killfieldengine@gmail.com>
Sun, 27 Jan 2013 13:03:02 +0000 (13:03 +0000)
committerDale Weiler <killfieldengine@gmail.com>
Sun, 27 Jan 2013 13:03:02 +0000 (13:03 +0000)
ftepp.c
tests/pp_va_args.qc
tests/pp_va_args.tmpl

diff --git a/ftepp.c b/ftepp.c
index b2697579f36b9df869a60e8e6626d8df64947697..b695edc24d03fae7f5b8df4f0fd27a6da9ae4fef 100644 (file)
--- a/ftepp.c
+++ b/ftepp.c
@@ -720,7 +720,7 @@ static bool ftepp_macro_expand(ftepp_t *ftepp, ppmacro *macro, macroparam *param
                 break;
 
             case TOKEN_VA_ARGS_ARRAY:
-                if (out->constval.i >= varargs) {
+                if ((size_t)out->constval.i >= varargs) {
                     ftepp_error(ftepp, "subscript of `[%u]` is out of bounds for `__VA_ARGS__`", out->constval.i);
                     vec_free(old_string);
                     return false;
index f54533b80f2e237a5eb97121f7fde1e54784b2c0..6e4002cf4315ca5384a1785ca908644e606038d4 100644 (file)
@@ -1,12 +1,21 @@
 void print(...) = #1;
 
-#define NOPARENS(...) __VA_ARGS__
-#define callem(func, args) func NOPARENS(args)
+// method 0
+#define METHOD__(...) __VA_ARGS__
+#define METHOD_0(F,A) F METHOD__(A)
 
-#define callen(func, ...) func __VA_ARGS__##[0]
+// method 1
+#define METHOD_1(F,A) F(METHOD__ A)
+
+// method 2
+#define METHOD_2(F,...) F __VA_ARGS__##[0]
+
+// method 3
+#define METHOD_3(F,...) F __VA_ARGS__
 
 void main() {
-    print(NOPARENS("hello ", "world\n"));
-    callem(print, ("Yay", ", there\n"));
-    callen(print, ("Woah",", there\n"));
+    METHOD_0(print, ("Method", " <zero>\n"));
+    METHOD_1(print, ("Method", " <one>\n"));
+    METHOD_2(print, ("Method", " <two>\n"));
+    METHOD_3(print, ("Method", " <three>\n"));
 }
index c6e0c14b53521cfc779a4b8389ea1a4962564f56..b3f30f6a9867d01891f63fe258f4fe99034c8948 100644 (file)
@@ -2,6 +2,7 @@ I: pp_va_args.qc
 D: __VA_ARGS__
 T: -execute
 C: -std=fteqcc
-M: hello world
-M: Yay, there
-M: Woah, there
+M: Method <zero>
+M: Method <one>
+M: Method <two>
+M: Method <three>