From: Blub Date: Sun, 28 Mar 2010 09:20:00 +0000 (+0000) Subject: (Commit created by redmine exporter script from page "NewQC" version 18) X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=3857fdf9060e8b71e605d994d6ddf50271dda6f3;p=xonotic%2Fxonotic.wiki.git (Commit created by redmine exporter script from page "NewQC" version 18) --- diff --git a/NewQC.textile b/NewQC.textile index 0245340..a5a33d4 100644 --- a/NewQC.textile +++ b/NewQC.textile @@ -59,3 +59,21 @@ float myfunc() final return 3; } + +h2. Variadic parameters + +Another "enhancement" is the possibility to have functions with variadic parameter lists. However, the only way to sanely access them (until pointers are allowed) is via a recursive way. +Here's an example that assumes float parameters and prints them one after the other: +
void printfloats(float count, float first, ...)
+{
+    if (count <= 0) // if there are no parameters, return
+        return;
+    if (count == 1) { // If there's one parameter, print it, plus a new-line
+        print(strcat(ftos(first), "\n"));
+        return;
+    }
+    // Otherwise we have multiple parameters left, so print the float, and add a comma
+    print(strcat(ftos(first), ", "));
+    myprint(count-1, ...);
+}
+So myprint(4, 1, 2, 3, 4) would print "1, 2, 3, 4\n"