switchstatements with initializers
std::unique_ptrMust Be Moved
Define flags at global scope in a
.cc file. Declare them at most once in a
Using header files is a reflex for most of us, so we may have forgotten why they are used:
#includeelsewhere. The entire program sees the same declaration.
.ccthat defines the same entity ensures the definition matches declaration.
You can do this incorrectly with no link-time error. First, place the following
// Defining --my_flag in a .cc file. ABSL_FLAG(std::string, my_flag, "", "My flag is a string.");
And the following, erroneous, declaration of the flag in a different
(perhaps a test):
// Declared in error: type should be std::string. extern absl::Flag<int64> FLAGS_my_flag;
The program is ill-formed, and whatever happens is the result of undefined behavior. In my test program, this code compiled, linked, and crashed when the flag was accessed.
Design with command line flags as you would global variables.
.hfile corresponding to its definition.
ABSL_FLAG(type, ...)macro to define flags.
Flags are global variables. Use them judiciously. Use and declare them as you would any other global variable.