Feature or bug: implicit cast from false to 0

  • Thread starter =?ISO-8859-2?Q?Mihajlo_Cvetanovi=E6?=
  • Start date
?

=?ISO-8859-2?Q?Mihajlo_Cvetanovi=E6?=

Observe this code (VC7.1):

void Test(const char*)
{
}

int main(void)
{
Test( false ); // OK
Test( true ); // error C2664: cannot convert from bool to const char*
}

Shouldn't the first call also produce the compiler error?
 
B

Bo Persson

Mihajlo Cvetanoviæ said:
Observe this code (VC7.1):

void Test(const char*)
{
}

int main(void)
{
Test( false ); // OK
Test( true ); // error C2664: cannot convert from bool to const
char*
}

Shouldn't the first call also produce the compiler error?


No - false, 0, NULL, 1 - 1, etc are all examples of constant integral
expressions, that can be used as the null pointer value.


Test(false) works just as well as Test(0) or Test(NULL).


Bo Persson
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top