[RESOLVED] The true bool assignment?
I'm back here after a bit of a pause.
Got a real simple question pertaining to the exact specification of the behavior of bool in the C++ language.
What is the proper method to assign a boolean value (data type bool) to the result of a comparison?
I know that in C the result of a comparison is specified to be of type int and its value either 0 or 1. However I am a bit uncertain how this might work in C++ with the variable type bool.
I tend to favor the second form in the sample below. However, I would prefer to use the first form. Although I fear that the first form might rely on an implicit cast which, as far as I am concerned, would be a possible form of concern regarding portability.
Can anyone comment on the proper way to set a bool to the result of a comparison?
Sincerely, Chris.
static int a(void) { return 1; }
static int b(void) { return 2; }
int main(void)
{
const bool a_LT_b_type01 = ::a() < ::b();
const bool a_LT_b_type02 = static_cast<bool>(::a() < ::b());
const bool a_LT_b_type03 = ::a() < ::b() ? true : false;
}

