Difference Between the Script and the C languages

Top  Previous  Next

 

The script files are written in a C-type language and you should not expect it to meet standards. Many features are not supported because they are not necessary and complication of the language can cause compiler errors (the script file language compiler is not a simple thing).

      Pointers are not directly supported. But arrays are supported, therefore a pointer can always be built from an array and element number. Note that, for example, string operation functions, such as strcpy, receive a string and a byte number (index) as parameters, which form the pointer. In function declarations, index is equal to zero by default.

      Pointers to functions are not supported. If necessary, a table call can always be replaced with the switch operator.

      Multidimensional arrays are not supported. If it is necessary, you can write a couple of functions, such as:

 int GetElement(int array[], int index1, int index2);

 void SetElement(int array[], int index1, int index2, int value);

      Structures (and unions) are not supported. In fact, you can always do without structures. Structures may be required for API Windows and user DLLs operations, but as a rule only experienced programmers should do it, such as those who know how to reach structure elements. As a tip, there are functions, such as memcpy, which receive a void "pointer").

      Enumerated types (enum) are not supported #define.

      Preprocessor macros, such as #define half(x) (x / 2), are not supported. The same operations can be done with functions.

      Conditional operators such as x = y == 2? 3 : 4;, are not supported; the operator "comma" outside variable declaration is not supported. For example,

int i = 0, j = 1; is supported, but

for (i = 0, j = 1; ...) is not supported.

      User functions with a variable amount of parameters are not supported. However, there are many system functions, such as printf, with a variable number of parameters.

      Declaration of user function parameters such as void array[] is not supported. The system functions such as memcpy, have such parameters.

      Logical expressions are always fully computed. It is very important to remember it, as a situation like

 char array[10];

 if (i < 10 && array[i] != 0)

   array[i] = 1;

will cause an error at the execution stage, if i is greater than 9, because the expression of array[i] will be computed. In a standard compiler such an expression is not computed, because the condition of i > 10 would cancel any further processing of the expression.

      Constant expressions are always computed during execution. For example, int i = 10 * 22 will be computed not during compilation, but during execution.

      The const key word is absent.

      Static variables cannot be declared inside functions.

But

      Variables can be declared anywhere, not just in front of the first executed operator. For example:

void main()

{

GlobalVar = 0;

int i = 1;       // will be OK as in C++

}

      Nested comments are allowed.

      Expressions like array = "1234" are allowed.

      Default parameter values in declared functions, as in C++, are allowed. For example, void func(char array[],int index = 0);. Expressions can also serve as default values, for example void func(char array[], int index = func1() + 1);.

      Expressions in global variable initializers are allowed. For example:

 float table[] = { sin(0), sin(0.1) };

 void main()

 {

   ...

 }