SETTYPE

Top  Previous  Next

Syntax

SETTYPE ptr as POINTER, type

Description

Sets the type of a pointer for automatic typecasting.

Parameters

ptr - A pointer variable

type - A built in or UDT type name.

Return value

None

Remarks

Pointers in Emergence BASIC are generic and don't generally point to a specific type of data. When using NEW the pointers type will be set to any built in variable type however UDT's will need to use SETTYPE or typecasting. A pointer defined as a parameter in a subroutine always needs to be explicitly set to a type with SETTYPE or always use typecasting. Either method produces the same output code.

See Also: TYPEOF

Example usage

TYPE MYUDT
    DEF age as INT
    DEF name as STRING
ENDTYPE
 
DEF pUdt as POINTER
pUdt = NEW(MYUDT,1)
 
'without SETTYPE using typecasting
#<MYUDT>pUdt.name = "Joe Smith"
#<MYUDT>pUdt.age = 7
 
'with SETTYPE
SETTYPE pUdt, MYUDT
#pUdt.name = "Joe Smith"
#pUdt.age = 7