Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return a list from the function using OUT parameter

Tags:

I would like to create a CMake function as:

function(test src_list dst_list) # do something endfunction() 

usage:

test(${my_list} chg_list) 

It means, my_list is a list with several fields, and chg_list will receive a list modified inside test function.

How can I create a function in CMake to do that?

like image 946
Alex Avatar asked Mar 18 '14 17:03

Alex


People also ask

How do you use out parameters in a function?

The out parameter in C# is used to pass arguments to methods by reference. It differs from the ref keyword in that it does not require parameter variables to be initialized before they are passed to a method. The out keyword must be explicitly declared in the method's definition​ as well as in the calling method.

What is an out parameter in C?

An out-parameter represents information that is passed from the function back to its caller. The function accomplishes that by storing a value into that parameter. Use call by reference or call by pointer for an out-parameter. For example, the following function has two in-parameters and two out-parameters.

What is out _ in C#?

The out is a keyword in C# which is used for the passing the arguments to methods as a reference type. It is generally used when a method returns multiple values.


1 Answers

In CMake, functions have their own scope, and by default, all modification of variables are local, unless you pass CACHE or PARENT_SCOPE as parameter to set. Inside a function, if you want to modify a variable in the scope of the caller, you should use:

set(${dst_list} <something> PARENT_SCOPE) 

See documentation:

A function opens a new scope: see set(var PARENT_SCOPE) for details.

like image 199
lrineau Avatar answered Sep 20 '22 12:09

lrineau