Example
The following C program demonstrates how related code can be aligned using elastic tabstops, even when using a proportional font. The coloured backgrounds show the tabstop grouping.
| const float SQRT2 |
= 1.41421356; |
/* square root of 2 */ |
| const float PI |
= 3.1416; |
/* mathematical constant pi */ |
/* This blank line prevents the red and yellow tabstops from combining */
| float volume_cylinder( |
float radius, |
|
float height) |
| { |
|
float volume = PI * radius * radius * height; |
| |
return volume; |
| } |
| int main |
| { |
|
float radius, height; |
|
for (height = 1.0; height <= 3.0; ++height) |
|
|
for (radius = 1.0; radius <= 3.0; ++radius) |
|
|
|
printf( |
"Volume of cylinder of height %.0f and radius %.0f is %.2f.\n", |
| |
|
|
|
height, |
|
|
|
|
radius, |
|
|
|
|
volume_cylinder(radius, height)); |
|
return 0; |
| } |
|
If the programmer, for example, changes the function name "volume_cylinder" to "volume" and constant name "PI" to "MATH_CONSTANT_PI", the code automatically realigns:
| const float SQRT2 |
= 1.41421356; |
/* square root of 2 */ |
| const float MATH_CONSTANT_PI |
= 3.1416; |
/* mathematical constant pi */ |
/* This blank line prevents the red and yellow tabstops from combining */
| float volume( |
float radius, |
|
float height) |
| { |
|
float volume = MATH_CONSTANT_PI * radius * radius * height; |
| |
return volume; |
| } |
| int main |
| { |
|
float radius, height; |
|
for (height = 1.0; height <= 3.0; ++height) |
|
|
for (radius = 1.0; radius <= 3.0; ++radius) |
|
|
|
printf( |
"Volume of cylinder of height %.0f and radius %.0f is %.2f.\n", |
| |
|
|
|
height, |
|
|
|
|
radius, |
|
|
|
|
volume(radius, height)); |
|
return 0; |
| } |
|