Target Language Compiler | ![]() ![]() |
Record Aliases
In TLC it is possible to create what is called an alias to a record. Aliases are similar to pointers to structures in C. You can create multiple aliases to a single record. Modifications to the aliased record are visible to every place which holds an alias.
The following code fragment illustrates the use of aliases.
%createrecord foo { field 1 } %createrecord a { } %createrecord b { } %createrecord c { } %addtorecord a foo foo %addtorecord b foo foo %addtorecord c foo { field 1 } %% notice we are not changing field through a or b. %assign foo.field = 2 ISALIAS(a.foo) = %<ISALIAS(a.foo)> ISALIAS(b.foo) = %<ISALIAS(b.foo)> ISALIAS(c.foo) = %<ISALIAS(c.foo)> a.foo.field = 2, %<a.foo.field> b.foo.field = 2, %<b.foo.field> c.foo.field = 1, %<c.foo.field> %% note that c.foo.field is unchanged
It is possible to create aliases to records which are not attached to any other records, as in the following example.
%function func(value) Output %createrecord foo { field value } %createrecord a { foo foo } ISALIAS(a.foo) = %<ISALIAS(a.foo)> %%return a.foo %return a.foo %endfunction %assign x = func(2) ISALIAS(x) = %<ISALIAS(x)> x = %<x> x.field = %<x.field>
Saving this script as alias_func.tlc
and invoking it with
produces the command window output
As long as there is some reference to a record through an alias, that record will not be deleted. This allows records to be used as return values from functions.
![]() | Records | TLC Files | ![]() |