Answers to this question state that scalars can be converted to _Bool
and that the resulting integer value of the _Bool
will be 0
or 1
.
The accepted answer to this question points out that pointers are scalars.
Is a failure to implicitly convert a pointer to a _Bool
, therefore, a compiler bug?
E.g.:
$ cat ./main.c
// main.c
#include <stdbool.h>
int main( int argc, char* argv )
{
int i;
int* p = &i;
bool foo = (bool)p;
bool bar = p;
return 0;
}
Failing compiler (one of one):
$ /path/to/mips_fp_le-gcc --version
2.95.3
$ /path/to/mips_fp_le-gcc ./main.c
./main.c: In function `main':
./main.c:10: incompatible types in initialization
Passing compiler (one of many):
$ gcc --version
gcc (GCC) 8.3.1 20190223 (Red Hat 8.3.1-2)
Copyright (C) 2018 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
$ gcc ./main.c
$
Note that only the implicit conversion, and not the cast (explicit conversion), is flagged as an error with the problem compiler.
Also, note that according to a comment to this question, the noted problem compiler is old - from 2001 - this may be relevant to whether this is a genuine compiler bug. (Reasons beyond my control prevent a version upgrade of the noted problem cross-compiler)