To answer the question: Not that way, no.
You could return a pointer to a malloc'd array containing multiple values.
Or return a pointer to a malloc'd struct containing multiple values
Or you could pass in pointers to storage locations as part of the arguments to this function, and set the values there.
Or you could shove some of the values into existing data structures, dynamic or static, that this function already has access to.
Or you could divide up an int or long into bitfields which carry the several values.
... There are probably other solutions.
Of course for any of these to work, the caller has to know what approach you're using and invoke the function properly.
But in C, the comma is NOT a solution for returning multiple values. The comma operator evaluates its two operands, discards the result of the first, and returns the second. So your sample is just looking at a
, throwing that away, and returning b
. Definitely not what you thought you were doing.
(And I should point out that C uses comma for several different purposes; the comma here is NOT the same as comma in an array initializer, for example.)
For what it's worth, I have used one language that permitted multi-value expressions separated by commas: CLU, which was an ancestor of a lot of the object-oriented languages. In CLU you could write statements like a,b=b,a
to exchange two values, or `r,theta=cartesianToPolar(x,y)" to do coordinate conversion. That was a nice feature, and easy to implement on modern stack machines.
(CLU had a number of other nice features that weren't picked up by later languages; I've always meant to go back and try to find out why not.)