LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   returning different types of variables from a function (https://www.linuxquestions.org/questions/programming-9/returning-different-types-of-variables-from-a-function-619618/)

knobby67 02-08-2008 09:41 AM

returning different types of variables from a function
 
Hi all,
is it possible to return different types of variables from a single function. eg int floats etc?

Matir 02-08-2008 10:13 AM

In what language? In C, you'd have to use a tagged union or something similar to overlap the values. C99 would permit an anonymous tagged union.

knobby67 02-08-2008 11:49 AM

Appologies yes C

vpsville 02-08-2008 08:53 PM

Quote:

Originally Posted by knobby67 (Post 3050354)
Hi all,
is it possible to return different types of variables from a single function. eg int floats etc?

The usual method (in C) would be to pass a list of parameters to the function (called a procedure in this case). These would have to be pointers to variables so the modifications within the function stick, otherwise you'll be modifying copies of the variables instead.

These parameters can be any kind of variable, including structures.

For example:

int myProc(int *i, float *f)
{
i++;
f += 3.14;

return true;
}


All times are GMT -5. The time now is 03:53 PM.