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

5 days ago

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.

1 day ago

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.

1 day ago

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.

1 2 3
Next ›   Last »