Live data from Hacker News

Beating C with one line of Brainfuck

kiwec.net

11–20 of 91 posts

Re: Beating C with one line of Brainfuck

#11
post #6

Generated C: #include char mem[30000] = { }; #define OUTPUTS 0 char outputs[OUTPUTS] = { }; int main() { char* ptr = mem + 0; fwrite(outputs, sizeof(char), OUTPUTS, stdout); ptr[2] = getchar(); ++ptr[2]; while (ptr[2]) { ptr[2] -= 11; while (ptr[2]) { ptr[2] -= 22; while (ptr[2]) { ++ptr[3]; --ptr[1]; while (ptr[1]) { ++*ptr; ++ptr[1]; } ptr[2] = 0; } ptr[2] = 0; } ptr[1] = 0; ptr[1] += ptr[3] * 1; ptr[3] = 0; ptr[2]…

Note that:

    #define OUTPUTS 0
    char outputs[OUTPUTS] = {  };
is not valid C (or C++) - zero length arrays are not a thing in either language,

Re: Beating C with one line of Brainfuck

#14

Is the 85MB test file available? I wasn't able to find it. I'd like to test this result against nerve [0], a brainfuck to x86_64 asm compiler I wrote (like funkicrab, it is also written in Rust). [0]: https://github.com/JoshMcguigan/nerve

Same here.

bff [1] has no fancy assembly, not even a compiler, just some basic loop unrolling and jump precomputation, but I too wonder how it compares to wc.

[1] https://github.com/apankrat/bff/

-- edit --

Found words.txt with 466551 words, so replicating it 28 times gets it to the OP's test size. Bff is ~5x slower than 'wc -w' ... which is not unexpected, but still slightly disappointing.

https://github.com/dwyl/english-words/blob/master/words.txt?...

Re: Beating C with one line of Brainfuck

#15
post #3

Marvelous. Anybody got an optimizing malbolge compiler?

Not an optimising one (yet) but a safe implementation of a malbolge interpreter written in Rust, which can run malbolge programs. Just for fun. https://github.com/return/malbolge

Has anyone used Rust to write an interpreter for INTERCAL yet?

Re: Beating C with one line of Brainfuck

#17
post #11
post #6

Generated C: #include char mem[30000] = { }; #define OUTPUTS 0 char outputs[OUTPUTS] = { }; int main() { char* ptr = mem + 0; fwrite(outputs, sizeof(char), OUTPUTS, stdout); ptr[2] = getchar(); ++ptr[2]; while (ptr[2]) { ptr[2] -= 11; while (ptr[2]) { ptr[2] -= 22; while (ptr[2]) { ++ptr[3]; --ptr[1]; while (ptr[1]) { ++*ptr; ++ptr[1]; } ptr[2] = 0; } ptr[2] = 0; } ptr[1] = 0; ptr[1] += ptr[3] * 1; ptr[3] = 0; ptr[2]…

Note that: #define OUTPUTS 0 char outputs[OUTPUTS] = { }; is not valid C (or C++) - zero length arrays are not a thing in either language,

  (base) jam@jam-XPS-8500:~/svn/src/music/mp3tomidi$ cc -c -Wall x.c
  (base) jam@jam-XPS-8500:~/svn/src/music/mp3tomidi$ cat x.c

  #define OUTPUTS 0
  char outputs[OUTPUTS] = {  };
Looks like you're wrong about that; at least for GNU C. It's not official C but if it works and generates no warnings it will be used too.

Long HN thread about this subject:

https://news.ycombinator.com/item?id=11674374

Zero length arrays are one of those things that C is renowned and notorious for: something that is useful at times but unpredictable because it is flirting with undefined behavior.

I usually compare C with a Formula 1 race car. It works well as long as you don't cut too many corners and when you do you end up plastered all over the road.

Re: Beating C with one line of Brainfuck

#18

Earlier quoted context omitted.

Not an optimising one (yet) but a safe implementation of a malbolge interpreter written in Rust, which can run malbolge programs. Just for fun. https://github.com/return/malbolge

Has anyone used Rust to write an interpreter for INTERCAL yet?

Wash your mouth out with FROMs :)

Re: Beating C with one line of Brainfuck

#19
post #11

Earlier quoted context omitted.

Note that: #define OUTPUTS 0 char outputs[OUTPUTS] = { }; is not valid C (or C++) - zero length arrays are not a thing in either language,

(base) jam@jam-XPS-8500:~/svn/src/music/mp3tomidi$ cc -c -Wall x.c (base) jam@jam-XPS-8500:~/svn/src/music/mp3tomidi$ cat x.c #define OUTPUTS 0 char outputs[OUTPUTS] = { }; Looks like you're wrong about that; at least for GNU C. It's not official C but if it works and generates no warnings it will be used too. Long HN thread about this subject: https://news.ycombinator.com/item?id=11674374 Zero length arrays are one…

     [neilb@Miranda temp]$ gcc -Wall -Wextra -pedantic a.c                  
      a.c:2:6: warning: ISO C forbids zero-size array   'outputs' [-Wpedantic] 
 char outputs[OUTPUTS] = {  };
Post reply on HN