Calling C Standard Library Functions
Cangjie uses the foreign keyword to declare external C functions, enabling you to directly call C standard library or custom C code. Since C functions may perform unsafe operations, all calls must be wrapped in unsafe blocks.
The foreign declaration only provides the function signature; the actual implementation resides on the C side. Parameters and return types must follow Cangjie-to-C type mapping rules: for example, Int32 corresponds to C's int32_t, and UIntNative corresponds to size_t. When using @C to decorate foreign declarations, it can be omitted since this is the default behavior.
The code on the right declares the abs and rand functions from the C standard library and calls them within unsafe blocks. At compile time, you need to link the C runtime library using cjc main.cj -lc.
foreign functions can only have declarations, not implementations. Variadic arguments are represented using ..., such as printf(fmt: CString, ...): Int32.Try adding a call to a foreign function on line 16 and see what compilation error occurs.