]> git.rm.cloudns.org Git - xonotic/xonotic.wiki.git/commitdiff
(Commit created by redmine exporter script from page "NewQC" version 18)
authorBlub <blub@speed.at>
Sun, 28 Mar 2010 09:20:00 +0000 (09:20 +0000)
committerRedmineExport <redmineexport@dev.xonotic.org>
Mon, 17 Nov 2014 17:53:33 +0000 (17:53 +0000)
NewQC.textile

index 0245340ba10071299000278d701ae2557ef47e88..a5a33d4e0218844830317a1c6083151b5dc665f2 100644 (file)
@@ -59,3 +59,21 @@ float myfunc() final
     return 3;
 }
 </pre>
+
+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:
+<pre>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, ...);
+}</pre>
+So <code>myprint(4, 1, 2, 3, 4)</code> would print <code>"1, 2, 3, 4\n"</code>