Why does intpromote spew warnings for ~ operator?

Alexey invalid at email.address
Tue Sep 14 08:42:20 UTC 2021


On Tuesday, 14 September 2021 at 07:29:39 UTC, jfondren wrote:
> On Tuesday, 14 September 2021 at 07:01:02 UTC, Alexey wrote:
>> On Tuesday, 14 September 2021 at 06:03:24 UTC, bauss wrote:
>>>a lot of C code is/will be
>>> ported to D
>>
>> mythical possibility
>
> I did this just the other day, translating 500 lines of a C 
> raylib implementation of Asteroids into D. Method: copy&paste 
> and fix errors. The most annoying bit was the extensive use of 
> C99 struct initializers, a lot of

Ok.

We have the situation, what in the code

```C
#include <stdio.h>

int main(int argc, char* argv[])
{
     unsigned char a = 0b100;
     unsigned int b = ~a;
     return 0;
}
```

in line `unsigned int b = ~a;` a is promoted to int before it's 
bit's flipped.

we also know what compiler should not silently to data 
transformations: for this reason D issues errors and warnings if 
it isn't sure what to do. but C, in example above, silently 
promotes a to int. - is this a good behavior? - is this behavior 
which D should inherit?

C can do also many other bad things silently - so what, should D 
support such behavior too? maybe D should silently support 
pointer magic, so C coder could easily copy-paste he's code to D?


More information about the Digitalmars-d mailing list