Variables, Data Types and Arrays

GPC supports only one primitive type: scalar integer.
      An integer is a number of the set Z = {..., -2, -1, 0, 1, 2, ...} which must be specified in decimal notation (base 10), optionally preceded by a sign ( - or + ). The integer type is represented by a 16 bits signed number, where the range is [-32768 ~ +32767]. The default initialized value is always zero.
int: 16 bits signed [-32768 ~ +32767]

  1. Declaring Variables

      A variable is just a place to store data in memory. Each variable has a name which start with a letter or underscore (_), followed by any number of letters, digits, or underscores. Uppercase is different from lowercase, so the names sam, Sam, and SAM specify three different variables. The scope of a variable is always global. Variables MUST be declared before the main procedure.
int var = 128, Var;  // 'var' initial value is 128, 'Var' initial value is 0
int VAR = -3;        // 'VAR' initial value is -3
    Var = var + VAR; // Var = 125
      Variables are always assigned by value. That is to say, after assigning one variable's value to another, changing one of those variables will have no effect on the other. GPC don't support assigning by reference.

  2. Arrays

      An array in GPC Scripting Language can be defined as number of memory locations, each of which can store the same data type (int) and which can be references through the same variable name and a index.
As the variables, arrays also must be declared before the main procedure. Standard array declaration is as:
int myarray[3];
    myarray[0] = 1;
    myarray[2] = 3;
    myarray[1] = myarray[0] + myarray[2];
      In GPC Language, arrays starts at position 0. The elements of the array occupy adjacent locations in memory. GPC Language process the name of an array as if it is a pointer to the first element. This is important in understanding how to do arithmetic with arrays. Any item in the array can be accessed through its index, and it can be accessed in any scope within the GPC script.
All elements of a array are initialized with 0. The GPC language doesn't support multidimensional arrays.

  3. Arrays Trick

      It is possible to use indexes with regular variables to access subsequent variables, as show in this code:
int a = 1, b = 2, c;
    a[2] = a[1] + a[0]; // Variable c has the value 3 (1 + 2)
    // a[0] == a;
    // a[1] == b;
    // a[2] == c;