This shows you the differences between two versions of the page.
| Next revision | Previous revision | ||
| multiple_return_values [2017/03/17 15:45] – created korshun | multiple_return_values [2019/04/21 21:32] (current) – korshun | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Multiple return values ====== | ====== Multiple return values ====== | ||
| - | acsutils uses a simple convention for functions | + | Some ACSUtils |
| - | There are global variables r1 through r8. The functions write their return | + | ACSUtils uses a convention to fake returning multiple values from a function. The convention is as follows: there are 8 global variables |
| - | | + | Here's an example, '' |
| - | int newX = r1; // Get the first returned | + | |
| - | int newY = r2; // And the second one | + | < |
| + | RotateVector(x, | ||
| + | int newX = r1; | ||
| + | int newY = r2; | ||
| + | </code> | ||
| + | |||
| + | <note warning> | ||
| + | You should retrieve | ||
| + | |||
| + | Don't do this: | ||
| + | < | ||
| + | SomeFunctionWithMultipleReturnValues(...); | ||
| + | SomeOtherFunction(r1); | ||
| + | int b = r2; | ||
| + | </ | ||
| + | Because '' | ||
| + | |||
| + | < | ||
| + | SomeFunctionWithMultipleReturnValues(...); | ||
| + | int a = r1; | ||
| + | int b = r2; | ||
| + | |||
| + | SomeOtherFunction(a); | ||
| + | </code> | ||
| + | </note> | ||
| + | |||
| + | <note important> | ||
| + | |||
| + | < | ||
| + | ParseFixed(" | ||
| + | int error = r1; | ||
| + | int result | ||
| + | </ | ||
| + | |||
| + | </ | ||
| + | |||
| + | But overwriting argument variables immediately after calling | ||
| + | < | ||
| + | RotateVector(x, | ||
| + | x = r1; | ||
| + | y = r2; | ||
| + | </ | ||
| + | |||
| + | An example of a function returning three values: | ||
| + | < | ||
| + | normalize3d(x, | ||
| + | int newX = r1; | ||
| + | int newY = r2; | ||
| + | int newZ = r3; | ||
| + | </ | ||
| - | <note warning> | ||