|
|
|
|
|
by johnbellone
4897 days ago
|
|
You're assuming that the first argument here is an integer value. For a single, one off, testing haress application I wouldn't worry too much about applying a full-blown semantic code style. Is there anything wrong with keeping the default value as a separate constant? const int kDefaultValue = 1000000;
int value = kDefaultValue;
if (argc > 1) {
value = std::atoi(argv[1]);
}
const int count = value;
Personally I much prefer using [program options][1] from the boost project (since we are talking about C++ here). Most projects already have this as a dependency, and its quite easy to setup. It also properly handles your types.[1]: http://www.boost.org/doc/libs/1_52_0/doc/html/program_option... |
|
I will agree, though, option parsing libraries are a definite must for released software. I like Boost, but using even small parts of it tends to pull everything in, and at least for my current project, we are trying to minimize dependencies (it's a library). I had to fight for Boost::regex, and only got it as a fallback for compiler versions that don't have regex.