November 02

On Saturday, 2 November 2024 at 18:01:45 UTC, IchorDev wrote:

>

Nope, not even close. That medal has to go to integer promotion.

That seems off-topic for this DIP thread.

>
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

November 03

On Friday, 1 November 2024 at 12:26:25 UTC, ryuukk_ wrote:

>
enum State
{
    IDLE,
    RUN,
    ATTACK,
}


fn void main()
{
    State state = IDLE;
    if (state == RUN) {
        // run
    }
}

D needs to to better

You want that magic in C and more. But D is a much more stable language

#include <assert.h>

typedef enum {
  One, Two, Three, Four
} Numbers;

typedef struct {
    size_t counter;
} S;


int main()
{
  assert(Four == 3);
  auto arr[] = { One, Two, Three, Four };

  int Four = 43;
  S myStruct = {
    counter : Four
  };
  assert(myStruct.counter == 43);
}

SDB@79

November 08

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:

>
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.

    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.

November 12

On Friday, 8 November 2024 at 20:20:19 UTC, IchorDev wrote:

>

I thought the point of requiring a cast after promotion was preventing under/overflow.

Thanks for spotting that, I added it to the issue tracker: https://issues.dlang.org/show_bug.cgi?id=24855

If you stumble on other failure cases, please add them as well.

November 12

On Tuesday, 12 November 2024 at 11:18:44 UTC, Dennis wrote:

>

On Friday, 8 November 2024 at 20:20:19 UTC, IchorDev wrote:

>

I thought the point of requiring a cast after promotion was preventing under/overflow.

Thanks for spotting that, I added it to the issue tracker: https://issues.dlang.org/show_bug.cgi?id=24855

If you stumble on other failure cases, please add them as well.

I tried to show the flaws of a feature and instead I found a bug. Classic. Thanks for opening the issue.
I still think VRP needs to be used with a lot of attention to detail in templated code to prevent errors when overflow is the desired outcome; whereas vomiting casts everywhere will only harm your eyes.

November 15

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:

>
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.

    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:

#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@79

1 2 3
Next ›   Last »