1[d=b] 是什么意思?

发布于 2024-12-02 05:35:10 字数 541 浏览 0 评论 0原文

我正在研究 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风吹过旳痕迹 2024-12-09 05:35:10

在 C 语言中,x[7]7[x] 之间没有区别。它们都等于 *(x+7) (和 *(7+x) 因为加法是可交换的),这意味着 x 的第七个元素代码>数组。

在本例中 (1[d=b]),您首先将 b 的当前值分配给 d,然后计算 1[d]d[1] 相同。

通过这种方式(offset[base] 而不是 base[offset]),它允许您将其与作业结合起来,否则您需要:

d = b; char *v = d[1];

我想我不需要告诉您这实际上是非常糟糕的代码,您必须非常努力地思考它的含义这一事实就证明了这一点。更好的代码几乎可以立即被解读。

In C, there is no difference between x[7] and 7[x]. They both equate to *(x+7) (and *(7+x) since addition is commutative) which means the seventh element of the x array.

In this particular case (1[d=b]), you first assign the current value of b to d, then calculate 1[d] which is the same as d[1].

By doing it this way (offset[base] rather than base[offset]), it allows you to combine it with the assignment, otherwise you'd need:

d = b; char *v = d[1];

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.

倚栏听风 2024-12-09 05:35:10

它索引到数组/指针d(刚刚分配了b的值)。相当于

d=b;
char*v=d[1];

在c中,数组和指针在很多方面可以用同样的方式处理;最值得注意的是,可以在两者上以相同的方式使用指针算术。 d[1] 等价于 *(d + 1),它又非常等价于 *(1 + d) - 反过来相当于1[d]

对于数组类型来说,使用索引表示法可能更为典型,但是(尤其是在混淆代码竞赛中;-)两者都可以用于任一类型。不过,不要在实际的生产代码中使用这些技巧...正如您可以证明的那样,它会让未来的维护人员的生活变得困难:-(

It indexes into the array/pointer d (which was just assigned the value of b). It is equivalent to

d=b;
char*v=d[1];

In 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 to 1[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 :-(

心凉怎暖 2024-12-09 05:35:10
a[b] is *(a + b)
b[a] is *(b + a)

所以

a[b] is b[a]

;

1[a] is a[1]

v=1[d=b]d=b v=d[1];

a[b] is *(a + b)
b[a] is *(b + a)

So

a[b] is b[a]

And

1[a] is a[1]

v=1[d=b] is d=b; v=d[1];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文