deprecate boolean evaluation of floating point and character types
Richard (Rikki) Andrew Cattermole
richard at cattermole.co.nz
Wed May 1 04:19:49 UTC 2024
On 01/05/2024 3:45 PM, Nicholas Wilson wrote:
> On Tuesday, 30 April 2024 at 18:09:22 UTC, Richard (Rikki) Andrew
> Cattermole wrote:
>> Characters are quite often compared against zero when doing string
>> handling in C without the binary expression. For this reason I would
>> not want to see this changed.
>
>
> D has the philosophy that valid C code should either behave the same in
> C as in D, or give an error (c.f. integer promotion rules). It is
> reasonable to make misleading behaviour like this an error.
Both C and D have the same behavior for characters.
```c
#include <stdio.h>
int main()
{
char c = 0;
if (c) {
printf("+\n");
}
return 0;
}
```
No output.
```d
import core.stdc.stdio;
void main()
{
char c = 0;
if (c) {
printf("+\n");
}
}
```
No output.
More information about the dip.ideas
mailing list