inout Parameters
The inout keyword is used to pass Cangjie variables by reference to CFunc. On the C side, the parameter type is CPointer<T>, while on the Cangjie side, you can pass a pointer by using inout to modify the variable.
There are several important constraints when using inout. First, the modified variable must be declared with var, not let constants or literals. Second, the variable's type must satisfy the CType constraint, but cannot be CString. Finally, variables modified with inout can only be used in calls to CFunc.
The pointer passed to the C side is only valid during the function call; the C side should not save this pointer for later use. Variables can be top-level variables, local variables, or struct members, but cannot directly or indirectly come from instance members of a class. The code on the right demonstrates modifying Cangjie variable values through pointers.
inout are only valid during the function call; the C side should not save this pointer for later use.Try modifying the code to use inout to pass multiple variables to a function simultaneously.
@C functions to demonstrate the C calling convention and inout. Replacing them with foreign declarations requires providing and linking the corresponding C implementation.