1[d=b] 是什么意思?
我正在研究 160 字节的 BrainFuck 代码,试图弄清楚它们的作用,但我似乎无法弄清楚 1[d=b] 的作用。
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;}
这是代码,大约在第一行的中间
http://j.mearie.org/post /1181041789/brainfuck-interpreter-in-2-lines-of-c
我不是问它在这种情况下做什么,而是问 1[] 在第一名。
谢谢=)
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 =)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
在 C 语言中,
x[7]
和7[x]
之间没有区别。它们都等于*(x+7)
(和*(7+x)
因为加法是可交换的),这意味着x
的第七个元素代码>数组。在本例中 (
1[d=b]
),您首先将b
的当前值分配给d
,然后计算1[d]
与d[1]
相同。通过这种方式(
offset[base]
而不是base[offset]
),它允许您将其与作业结合起来,否则您需要:我想我不需要告诉您这实际上是非常糟糕的代码,您必须非常努力地思考它的含义这一事实就证明了这一点。更好的代码几乎可以立即被解读。
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 thex
array.In this particular case (
1[d=b]
), you first assign the current value ofb
tod
, 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.
它索引到数组/指针
d
(刚刚分配了b
的值)。相当于在c中,数组和指针在很多方面可以用同样的方式处理;最值得注意的是,可以在两者上以相同的方式使用指针算术。
d[1]
等价于*(d + 1)
,它又非常等价于*(1 + d)
- 反过来相当于1[d]
!对于数组类型来说,使用索引表示法可能更为典型,但是(尤其是在混淆代码竞赛中;-)两者都可以用于任一类型。不过,不要在实际的生产代码中使用这些技巧...正如您可以证明的那样,它会让未来的维护人员的生活变得困难:-(
It indexes into the array/pointer
d
(which was just assigned the value ofb
). It is equivalent toIn c, arrays and pointers can be handled the same way in many respects; most notably that one can use pointer arithmetic the same way on both.
d[1]
is equivalent to*(d + 1)
, which is trivially equivalent to*(1 + d)
- which in turn is equivalent to1[d]
!Using the index notation may be more typical for array types, but (especially in obfuscated code contests ;-) both can be used on either type. Don't use such tricks in real, production code though... as you can testify, it can make future maintainers' life difficult :-(
所以
;
v=1[d=b]
是d=b v=d[1];
So
And
v=1[d=b]
isd=b; v=d[1];