ruslo / CGold

:whale2: The Hitchhiker’s Guide to the CMake
https://cgold.readthedocs.io
BSD 2-Clause "Simplified" License
521 stars 57 forks source link

Is it possible to send return value via argument? #41

Closed stevenleeS0ht closed 5 years ago

stevenleeS0ht commented 5 years ago

In Return Value, it recommends to set a variable to the parent scope to return a value from function.

But I am wondering if it is possible to return a value via argument of function. It is more commonly seen in CMake for example: ProcessorCount(N), N is a output argument of function.

Is the function argument in CMake passed by reference?

ruslo commented 5 years ago

if it is possible to return a value via argument of function

You're passing the name of the variable and in function you set this variable to PARENT_SCOPE.

It is more commonly seen in CMake for example: ProcessorCount(N), N is a output argument of function.

It's not common at all. It can be used for the functions with a trivial signature. Widely used approach is somefunc(SOMEPARAM somevalue). E.g.:

Is the function argument in CMake passed by reference?

There is no such thing in CMake language. It's the same PARENT_SCOPE:

ruslo commented 5 years ago

Closing inactive discussion.