From 0c66d87abe077e76dbf306381d5ae226337c8bf3 Mon Sep 17 00:00:00 2001 From: divVerent Date: Wed, 4 Jul 2012 14:20:00 +0000 Subject: [PATCH] (Commit created by redmine exporter script from page "Introduction_to_QuakeC" version 8) --- Introduction_to_QuakeC.textile | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/Introduction_to_QuakeC.textile b/Introduction_to_QuakeC.textile index c145c0a..792b544 100644 --- a/Introduction_to_QuakeC.textile +++ b/Introduction_to_QuakeC.textile @@ -70,22 +70,30 @@ h2. Declaring To declare a variable, the syntax is the same as in C: +

   float i;
+
However, variables cannot be initialized in their declaration for historical reasons, and trying to do so would define a constant. Whenever a variable declaration could be interpreted as something else by the compiler, the _var_ keyword helps disambiguating. For example, +

   float(float a, float b) myfunc;
+
is an old-style function declaration, while +

   var float(float a, float b) myfunc;
+
declares a variable of function type. An alternate and often more readable way to disambiguate variable declarations is using a _typedef_, like so: +

   typedef float(float, float) myfunc_t;
   myfunc_t myfunc;
+
h2. Scope @@ -125,14 +133,16 @@ A _string_ in QuakeC is an immutable reference to a null-terminated character st * *ftos* and *vtos* convert _floats_ and _vectors_ to strings. Their inverses are, of course, _stof_ and _stov_, which parse a _string_ into a _float_ or a _vector_. * *strcat* concatenates 2 to 8 strings together, as in: -
+

 strcat("a", "b", "c")=="abc";
-
+
* *strstrofs(haystack, needle, offset)* searches for an occurrence of one string in another, as in: -
+

 strstrofs("haystack", "ac", 0)==5;
-
The offset defines from which starting position to search, and the return value is _-1_ if no match is found. The offset returned is _0_-based, and to search in the whole string, a start offset of _0_ would be used. +
+ +The offset defines from which starting position to search, and the return value is _-1_ if no match is found. The offset returned is _0_-based, and to search in the whole string, a start offset of _0_ would be used. * *substring(string, startpos, length)* returns part of a string. The offset is _0_-based here, too. @@ -141,13 +151,13 @@ Note that there are different kinds of _strings_, regarding memory management: * *Allocated strings* are strings that are explicitly allocated. They are returned by _strzone_ and persist until they are freed (using _strunzone_). Note that _strzone_ does not change the string given as a parameter, but returns the newly allocated string and keeps the passed temporary string the same way! That means: ** To allocate a string, do for example: -
+

 myglobal = strzone(strcat("hello ", "world"));
-
+
** To free the string when it is no longer needed, do: -
+

 strunzone(myglobal);
-
+
* *Engine-owned strings*, such as _netname_. These should be treated just like temporary strings: if you want to keep them in your own variables, _strzone_ them. -- 2.39.2