]> de.git.xonotic.org Git - xonotic/xonotic.wiki.git/commitdiff
qc function syntax
authorMartin Taibr <taibr.martin@gmail.com>
Sun, 30 Jun 2019 04:16:53 +0000 (06:16 +0200)
committerMartin Taibr <taibr.martin@gmail.com>
Sun, 30 Jun 2019 04:16:53 +0000 (06:16 +0200)
Archive.md
Home.md
Introduction-to-QuakeC.md

index ba962a05056d40abc0d591544b918c99b0999c50..599a8548ca2fb7dddf3f025917d37390fcd20889 100644 (file)
@@ -36,3 +36,4 @@ Other
 [Roles](Roles) - roles and skills of contributing community members - outdated list of stuff nobody kept of to date  
 [Community development](Community-development) - another outdated list  
 [Art Roadmap](Art-Roadmap)  
+[NewQC](NewQC) - possible changes regarding QC (compiler, syntax, …) - never happened so the syntax descriptions are mostly wrong  
diff --git a/Home.md b/Home.md
index f68a823ff7a636ab65a9f8dd484c27458793e462..e3e74290e34aece436ec5919aba38a805e5e58e9 100644 (file)
--- a/Home.md
+++ b/Home.md
@@ -123,7 +123,6 @@ Mutators change the configuration of the game play, e.g. how weapon appears, whi
 -   [DarkPlaces Wiki](DarkPlaces-Index)
 -   [QuakeC Specifications v1.0](QuakeC-Wiki)
 -   [QuakeC tutorials](http://www.inside3d.com/tutorials.php) at inside3d.com
--   [NewQC](NewQC) - Possible changes regarding QC (compiler, syntax, …)
 -   [Writing your first mutator](writing-your-first-mutator)
 -   [Tips for new developers](Programming-Tips)
 
index bf7071169ee1b0514ed5b1ba2f4af372ab723b74..2dea2c590c3f7f64f6c62ca7701027f8ed77d826 100644 (file)
@@ -246,9 +246,12 @@ float sum3(float a, float b, float c)
 However, the syntax to declare function pointers is simplified:
 
 ```c
+// in global scope
 typedef float(float, float, float) op3func_t;
 var float(float a, float b, float c) f;
 op3func_t g;
+
+// in local scope
 f = sum3;
 g = f;
 print(ftos(g(1, 2, 3)), "\n"); // prints 6
@@ -270,6 +273,23 @@ A special kind of functions are the built-in functions, which are defined by the
 string strcat(string a, string b, ...) = #115;
 ```
 
+The function/field syntax is ambiguous. In global scope a declaration can be a variable, field or function. In local scope, it's always a variable. The `var` keyword can be used in global scope to treat is as local scope (always declaring a variable). The following table shows declarations in global scope:
+
+| Example code | Meaning |
+| `.float a;` | Entity field of type `float` |
+| `float(float x1) a;` or `float a(float x1);` | Function with a `float` param returning `float` |
+| `.float a(float x1);` | Function with a float param returning a `float` field reference |
+| `.float(float x1) a;` | Entity field of type function with a `float` param returning `float` |
+| `.float(float x1) a(float x2);` | Function with a `float` param returning a field reference of type function with a `float` param returning `float` |
+
+These rules were determined by experimenting with GMQCC:
+- if there are parentheses after the name, it's always a function
+- else if it starts with a period, it's a field
+- else if there are parentheses after the type, it's a function (using the old QC syntax)
+- else it's a variable
+
+GMQCC allows even weirder declarations like `float f(float)();` which can be called as `f()(42);`. It's not clear whether this behavior is intentional or the result of one of the many compiler bugs.
+
 void
 ----