I was working through the 160 byte BrainFuck code trying to figure out what things do, and I cant seem to figure out what 1[d=b] does.
s[99],*r=s,*d,c;main(a,b){char*v=1[d=b];for(;c=*v++%93;)for(b=c&2,b=c%7?a&&(c&17
?c&1?(*r+=b-1):(r+=b-1):syscall(4-!b,b,r,1),0):v;b&&c|a**r;v=d)main(!c,&a);d=v;}
Heres the code, its about midway through the first line
http://j.mearie.org/post/1181041789/brainfuck-interpreter-in-2-lines-of-c
I’m not asking what it does in that context but what 1[] does in the first place.
Thanks =)
In C, there is no difference between
x[7]and7[x]. They both equate to*(x+7)(and*(7+x)since addition is commutative) which means the seventh element of thexarray.In this particular case (
1[d=b]), you first assign the current value ofbtod, then calculate1[d]which is the same asd[1].By doing it this way (
offset[base]rather thanbase[offset]), it allows you to combine it with the assignment, otherwise you’d need:I suppose I shouldn’t need to tell you that this is actually very bad code, as evidenced by the fact that you have to think very hard about what it means. Better code would be almost instantly decipherable.