MQL4 Reference Language Basics Operations and Expressions Other Operations
Other operationsIndexing ( [] )When addressing the i-th element of the array, the expression value is the value of a variable with the serial number i. Example:
Only an integer can be index of an array. Four-dimensional and below arrays are allowed. Each dimension is indexed from 0 to dimension size-1. In particular case, for a one-dimensional array consisting of 50 elements, the reference to the first element will look like array [0], that to the last element will be array [49]. When addressing beyond the array, the executing subsystem will generate a critical error, and the program will be stopped. Calling Function with x1, x2 ,..., xn ArgumentsEach argument can represent a constant, variable, or expression of the corresponding type. The arguments passed are separated by commas and must be inside of parentheses, the opening parenthesis must follow the name of the called function. The expression value is the value returned by the function. If the return value is of void type, such function call cannot be placed to the right in the assignment operation. Please make sure that the expressions x1,..., xn are executed exactly in this order. Example:
Comma Operation ( , )Expressions separated by commas are executed from left to right. All side effects of the left expression calculation can appear before the right expression is calculated. The result type and value coincide with those of the right expression. The list of parameters to be passed (see above) can be considered as an example. Example:
Dot Operator ( . )For the direct access to the public members of structures and classes the dot operation is used. Syntax:
Example:
Scope Resolution Operation ( :: )Each function in a mql4 program has its own execution scope. For example, the Print() system function is performed in a global scope. Imported functions are called in the scope of the corresponding import. Method functions of classes have the scope of the corresponding class. The syntax of the scope resolution operation is as follows:
If there is no scope name, this is the explicit direction to use the global scope. If there is no scope resolution operation, the function is sought in the nearest scope. If there is no function in the local scope, the search is conducted in the global scope. The scope resolution operation is also used to define function-class member.
Use of several functions of the same name from different execution contexts in a program may cause ambiguity. The priority order of function calls without explicit scope specification is the following:
To avoid the ambiguity of function calls, always explicitly specify the function scope using the scope resolution operation.
Example:
Operation of Obtaining Data Type Size or Size of Any Data Type Object ( sizeof )Using the sizeof operation, the memory size corresponding to an identifier or type can be defined. The sizeof operation is of the following format: Example:
Any identifier, or type name enclosed in brackets can be used as an expression. Note that the void type name can't be used, and the identifier cannot belong to the field of bits, or be a function name. If the expression is the name of a static array (i.e. the first dimension is given), then the result is the size of the whole array (i.e. the product of the number of elements and the length of the type). If the expression is the name of a dynamic array (the first dimension is not specified), the result will be the size of the object of the dynamic array. When sizeof is applied to the name of structure or class type, or to the identifier of the structure or class type, the result is the actual size of the structure or class. Example:
The size is calculated at the compilation stage. See also
|