use 0 instead of NULL because gcc complains about conversion from NULL to int type (intptr_t)
convert code to a version that is agreable to gcc (and, apparently, C++ standard)
in C++ proper, apparently we can't forward-declare enums, and gcc enforces that
use std::min(), std::max() instead of min/max macros and dis-ambiguate some invocations