Function (method or object) returning 3 values?

I am not quite sure about the programming language used for the Arduino so I have a question about functions (or maybe objects or method).

I want to make a function that take three integer inputs (x, y, z) and returns three Boolean outputs (a, b, c). (to simplify variable names)

A function or method only returns one value, right?

Can I make an object (named “states” for example) like in java and keep track of states.a, states.b, and states.c? Are objects with local variables and methods part of the Android programming language? Do objects have constructors and methods like in Java?

Thanks for any tips for how to have a 3 input, 3 output function (method or object)?
Drew

A function or method only returns one value, right?

A function returns one item.
The item could be a struct. (hint)

Or you could pass the booleans by reference.

I see, thanks for the hint! I think I have it worked out now with the function returning a structure from this page:

I guess since all elements of my structure will be the same type (boolean). I could just have the function return an array instead of a struct? (or a pointer to an array more exactly). I found a page discussing that here:

Any preference for one over another?

  • A function returning a structure of three booleans
  • A function returning an array (pointer) of three booleans?

Thank for the help!
Drew

I'm not sure of this answer, but I think passing a structure copies the entire structure and puts it on the stack. A pointer would only place the lvalue of the structure (i.e., the 2-byte memory address where the structure is located in memory) on the stack. So I would expect the pointer version to be quicker and probably use a little less memory.

Any preference for one over another?

  • A function returning a structure of three booleans
  • A function returning an array (pointer) of three booleans?

A function can not return an array. It can return a pointer to an array, but the array must either be global, in which case returning a pointer to it is silly, or static.