Since the ultimate goal here is the parsing of command line options, why not wrap all the option variables in a single class, make them const, and have main() call a function (passing argc and argv) which validates the arguments, builds the options object and returns it? If the options do not validate properly, throw an exception.
Code:
class program_options
{
public:
program_options(int unit_val, int other_val, int foo_val, ...)
: UNIT(unit_val),
OTHER(other_val),
FOO(foo_val)
...
{
}
// Since the options are const, make them public, accessible directly
const int UNIT;
const int OTHER;
const int FOO;
...
};
program_options get_program_options(int argc, char **argv)
{
if(options_not_valid())
{
throw program_option_exception();
}
...
return program_options(unit_val, other_val, foo_val, ...)
}
int main(int argc, char **argv)
{
try
{
program_options opts = get_program_options(argc, argv);
run_program(opts);
return 0;
}
catch(program_option_exception e)
{
show_usage_message();
exit(1);
}
return 0;
}