// This example only works with the GCC!
//
// Also, it uses goto gratuitously -- this would have been
// better (and easier) done with any other control construct.
#include <iostream>
#include <limits>
usingnamespace std;
int main()
{
void* computed_goto;
int age;
cout << "How old are you? " << flush;
cin >> age;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
if (age < 21) computed_goto = &&too_young;
elseif (age >= 65) computed_goto = &&too_old;
else computed_goto = && just_right;
goto *computed_goto;
too_young:
cout << "You're too young!\n";
goto the_end;
too_old:
cout << "You're too old!\n";
goto the_end;
just_right:
cout << "Hello!\n";
the_end:
cout << "Press ENTER to quit..." << flush;
cin.ignore( numeric_limits <streamsize> ::max(), '\n' );
return 0;
}
This feature exists for the creation of jump tables... See section 5.3 of the latest GCC documentation. (And for better examples of how to use it in a jump table.)