Statements

Shroud can be thought of as a fancy macro processor. The statement data structure is used to define code that should be used to create the wrapper. Combinations of language, type and attributes are used to select a statement entry.

Passing function result as an argument

This section explains how statements are used to generate code for functions which return a struct.

Compiler ABI do not agree on how some function results should be returned. To ensure portablity, some function results must be passed as an additional argument. This is typically more complicated types such as struct or complex.

    dict(
        name="f_function_struct_scalar",
        alias=[
            "c_function_struct_scalar",
        ],
        f_arg_call=["{f_var}"],

        c_arg_decl=["{c_type} *{c_var}"],
        i_arg_decl=["{f_type}, intent(OUT) :: {c_var}"],
        i_arg_names=["{c_var}"],
        i_import=["{f_kind}"],
        c_return_type="void",  # Convert to function.
        cxx_local_var="result",
        c_post_call=[
            "memcpy((void *) {c_var}, (void *) &{cxx_var}, sizeof({cxx_var}));",
        ],
    ),