From 47450d8db544ac585c25e82f84bea4b0ce0c63ef Mon Sep 17 00:00:00 2001 From: Martin Taibr Date: Sun, 30 Jun 2019 06:16:53 +0200 Subject: [PATCH] qc function syntax --- Archive.md | 1 + Home.md | 1 - Introduction-to-QuakeC.md | 20 ++++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/Archive.md b/Archive.md index ba962a0..599a854 100644 --- a/Archive.md +++ b/Archive.md @@ -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 f68a823..e3e7429 100644 --- 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) diff --git a/Introduction-to-QuakeC.md b/Introduction-to-QuakeC.md index bf70711..2dea2c5 100644 --- a/Introduction-to-QuakeC.md +++ b/Introduction-to-QuakeC.md @@ -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 ---- -- 2.39.2