Allow designated initialization of struct
    Salih Dincer 
    salihdb at hotmail.com
       
    Fri Nov 15 05:44:39 UTC 2024
    
    
  
On Friday, 8 November 2024 at 20:20:19 UTC, IchorDev wrote:
> On Saturday, 2 November 2024 at 20:21:57 UTC, Nick Treleaven 
> wrote:
>> On Saturday, 2 November 2024 at 18:01:45 UTC, IchorDev wrote:
>>> ```d
>>> short x = 127;
>>> short y = x / 2 + 1; //Error: integer promotion screwed you 
>>> over again!
>>
>> Actually that example compiles fine due to VRP.
>> https://dlang.org/spec/type.html#vrp
>
> Which shouldn’t be relied on to prevent integer under/overflow 
> because it allows it.
> ```d
>     short x = short.max;
>     short div = 1;
>     short y = x / div + 1;
> ```
> I thought the point of requiring a cast after promotion was 
> preventing under/overflow.
Compiler version gcc 6.3.0 also allows this and you get the same 
result. Here is the code:
```c
#include <stdio.h>
#include <limits.h>
int main()
{
     short x = SHRT_MAX;
     short div = 1;
     short y = x / div + 1;
     printf("%d > %d\n", x, y);
     // 32767 > -32768
     return 0;
}
```
SDB at 79
    
    
More information about the dip.ideas
mailing list