News for hackers. Stuff that matters.
Re:Arduino-copilot makes it easy to use Haskell to program a... by joeyh on Sunday January 26, 2020 @09:28AM (#22152200)
Doing some constant folding, the C compiler would arrive at something like this:

    void loop(void) {
      delay(100);
      digitalWrite(13, s0[s0_idx]);
      s0[s0_idx] = s0[s0_idx];
      s0_idx = (++s0_idx) % 2;
    }
    void setup()
    {
      pinMode(13, OUTPUT);
    }
Only the s0[s0_idx] = s0[s0_idx] looks like extra work now. I don't know if a C compiler would optimise that away, but assuming it does not, one extra memory write per loop is not bad overhead.

There are no comments on this comment yet.