Gentee Programming Language > Documentation > Syntax | Download documentation |
The . operator is used to access a field value or method call.
<field> ::= <object>'.'<field name>
type customer // we define type Customer { str name, last_name uint age arr phones[ 5 ] of str } ... ... customer cust1 //we create a variable of type Customer cust1.name = "Tom" cust1.age = 30 cust1.phones[ 0 ] = "3332244"
The unary operator & gives the address of a local or global variable as well as the address of a function. The operation returns the value of uint type. However, if the result of any operation is an object, for example the function which returns a string, the address-of operator is also apllied to the obtained object. The address-of operator &, applied to the object (structure), returns the address of the required object and is used for a type cast to uint type.
uint a b str mystr ... a = &mystr //The address of the object mystr is assigned to variable a b = &getsomestr() //The address of the returned object is assigned to variable b
The pointer and the typecasting operator -> access a pointer value. The right-hand operand must be a type name. If the left-hand operand is an operand of uint type and the right-hand operand is a name of any fundamental type (an integer or a floating-point number), the left operator is treated as a pointer to the given type. The result of the operation is likely to be an lvalue, therefore a pointer value can be modified. Otherwise, the -> operator is used for a type cast.
<pointer> ::= <expression>'->'<type name> [<array>]
int a = 10, b uint addra addra = &a b = addra->int // b is equal to 10 addra->int = 3 // a is equal to 3
If the right-hand operand is a name of the structure type, you can use the '.'operator after a pointer value has been accessed.
customer cust1 uint pcust pcust = &cust1 pcust->customer.name = "Tom"
The -> operation appears in an extended syntax provided that the object is designated by its pointer and you need to access the object element. In addition to the type, you have to specify the object's dimension and the element type. The object's dimension is enclosed in square brackets. If a one-dimensional array is specified, you do not need to use the square brackets; if you specify a two-dimensional array, a comma is used inside the square brackets; in case of a three-dimensional array, use two commas inside the square brackets, etc. It closely resembles declaring variables of such a type, nevertheless values of dimensions are not specified. If the element type differs from uint type, the type name is defined using the keyword of. Then the operation of retrieving elements may be applied.
arr myarr[ 10, 10 ] of byte uint a a = &myarr //The compiler loses element type and dimensional data (a->arr[,] of byte)[1,1] = 10
See also
The As Operator, Type Redefinition Table Of Operator Precedence
![]() |
![]() Copyright © 2004-2006 Gentee Inc. All rights reserved. ![]() |