ATS puts great emphasis on interacting with other programming languages.
Suppose that I have in some C code a (global) integer variable of the name foo and I want to increase in some ATS code the value stored in foo by 1. This can be done as follows:
val x0 = $extval(int, "foo") // get the value of foo val p_foo = $extval(ptr, "&foo") // get the address of foo val () = $UNSAFE.ptr_set<int> (p_foo, x0 + 1) // update foo
As for another example, let us suppose that foo2 is a record variable that contains two integer fields named first and second. Then the following code assigns integers 1 and 2 to these two fields of foo2:
By its very nature, the feature of extvar-declaration is inherently unsafe, and it should only be used with caution.Please find on-line the entirety of the code presented in this chapter.