.qc (dot qc) - the group for quake c coders of all denominations. If you make quake one mods and write code in quake c, join our group! I'll try to answer any quake c questions - please post your inquiry in the forums...

Forum Thread
  Posts  
Conserve global variables - use "null_string" (Groups : qc : Forum : vault() : Conserve global variables - use "null_string") Locked
Thread Options
numbersix
numbersix quake-c coder++
Nov 17 2013 Anchor

Coding quake-c harks back to an older day. It makes me mindful of 6502 and Z80 coding.

I have recently discovered global variables have a hard limit - 32768.

These are all examples of global variables

float i; 
string s; 
void() SUB_Null = { }; 
void() catch = 
{ 
  local float f; 
  local vector v; 
  bprint("Hello!\n"); 
  i = f = 42; 
  s = "another freaking global"; 
  return(666); 
};

void() gravity_pulse1 = [ $cubelf01, gravity_pulse2 ] { SUB_Null (); }; 
void() gravity_pulse2 = [ $cubelf02, gravity_pulse3 ] { SUB_Null (); }; 
void() gravity_pulse3 = [ $cubelf03, gravity_pulse1 ] { SUB_Null (); };

Every line in the examples above loads another global variable. That is 15 globals in that example.
(The vector counts as 3 globals - 3 floats!)

Yes, the local variables are globals. Yes, the function defines are globals.

And yes, the literals like 42, and "Hello!\n" are...you guessed it, globals.

I found this trick with fteqcc - Replace all null string references "" (two quotes) with:

string null_string = ""; // at the end of defs.qc

instead of:

if (s == "") SUB_Null();

use:

if (s == null_string) SUB_Null();

Every instance will save you one global variable.

Update:

V106 qc already does this with -

defs.qc:string string_null; // null string, nothing should be held here


Edited by: numbersix

Reply to thread
click to sign in and post

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.