External Types and Values in ATS

External types and values can be readily formed in ATS to refer to types and values declared in C.

Suppose that there is a type in C of the name some_type_in_c, then this type can be referred to in ATS as $extype"some_type_in_c". For instance, type definitions are introduced in the following code for some external types in C:

typedef Cint = $extype"int" typedef Clint = $extype"long int" typedef Cllint = $extype"long long int" typedef Cint2 = $extype"struct{ int x; int y; }"

Suppose that there is a value in C of the name some_value_in_c, then this value can be referred to in ATS as $extval(T, "some_value_in_c"), where T is a type in ATS assigned to this value. For instance, macro definitions are introduced in the following code for some external values in C:

macdef NULL = $extval(ptr, "0") macdef stdin_ref = $extval(FILEref, "stdin") macdef stdout_ref = $extval(FILEref, "stdout")

External values can also be formed to refer to functions in C as done in the following code:

macdef atoi = $extval(string -> int, "atoi") macdef atol = $extval(string -> lint, "atol") macdef atof = $extval(string -> double, "atof")

Note that there are other ways in ATS that are often more approriate for directly referring to functions in C. Typically, the primary purpose of forming an external value in ATS is to allow a constant declared in C to be directly referred to in ATS code.