Life time of pointers

Hi :wave:

I have noticed that, in many places, ACADOS’ C interface uses signatures like the following for setting data:

void ocp_nlp_out_set(ocp_nlp_config *config, ocp_nlp_dims *dims, ocp_nlp_out *out,
        int stage, const char *field, void *value);

To me, this conveys that value needs to outlive the solver. const void* on the other hand, would at least somewhat imply that the contents are copied.

Is the data copied in these cases? Can I discard value after calling the function?

Hi,

yes the data is always copied, although the function does not have const in its signature.

1 Like