Next: , Previous: Blocks and conditional as expressions, Up: Extensions to C


2.1.2.2 Tuples

Tuples are a way to manipulate several values at once.

Creating a new tuple does not allocate memory. Tuples don't have addresses, their content is not placed contiguously in memory. They really are just a way to consider several values at once.

For instance, the tuple (4, 5, 'toto') is a constant. Thus you can create multiple-values constants with L.

When a tuple contain complex expressions (that is to say, anything except a constant or a variable), the order of evaluation is defined to be from the left to the right.

Finally, on an implementation note, using tuple is higly efficient, because each component of a tuple can be a register.

For instance, the (a,b) = (b,a) construct may use the efficient xchg instruction on CISC machines; It is difficult for a standard C compiler to use these instructions, and the corresponding code would use three instructions and a supplementary register.

Tuple is thus an both a pleasant and efficient abstraction.

Note: Depending on the architecture, Word64 can be or not a tuple. But most code can ignore this fact and completly ignore the issue.