什么是为preventing分配数组的理由? [英] What's the rationale for preventing assignment to arrays?

查看:97
本文介绍了什么是为preventing分配数组的理由?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图谷歌这一点,并已阅读:

I've tried to google this and have read:

  • Why can't arrays of same type and size be assigned?
  • Assigning arrays
  • Assign to array in struct in c

但他们都说出显而易见的:你不能分配给数组因为标准是这样说的。这是伟大的,但是我想知道的为什么的标准不包括分配给阵列的支持。该标准委员会详细讨论事情,我会感到惊讶,如果他们从来没有讨论过做数组分配。假设他们已经讨论过,他们必须有没有让一些数组理被分配到。

But they all state the obvious: you can't assign to arrays because the standard says so. That's great and all, but I want to know why the standard doesn't include support for assigning to arrays. The standard committee discusses things in detail, and I'd be surprised if they never discussed making arrays assignable. Assuming they've discussed it, they must have some rationale for not letting arrays be assigned to.

我的意思是,我们可以把一个阵列中的结构和分配给结构就好了:

I mean, we can put an array in a struct and assign to the struct just fine:

struct wrapper
{
    int array[2];
};

struct wrapper a = {{1, 2}};
struct wrapper b = {{3, 4}};
a = b; // legal

但直接使用数组是禁止的,即使它有效地完成同样的事情:

But using an array directly is prohibited, even though it accomplishes effectively the same thing:

int a[2] = {1, 2};
int b[2] = {3, 4};
a = b; // Not legal

什么是标准委员会关于禁止分配给数组理由?

What is the standard committee's rationale for prohibiting assigning to arrays?

推荐答案

记者了解到,意图的不是的制作阵列前pressions无法分配;这不是目标 1 。相反,这种行为就掉下来一个设计决定的里奇提出,简化阵列中的编译器处理,但在交流方面阵列前pressions二等的对象;他们失去了阵性在大多数情况下。

Understand that the intent wasn't to make array expressions unassignable; that wasn't the goal1. Rather, this behavior falls out of a design decision Ritchie made that simplified array handling in the compiler, but in exchange made arrays expressions "second-class" objects; they lose their "array-ness" in most contexts.

本文(尤其是名为胚胎的部分C)的一些背景;我也有一个更详细的解答<一个href=\"http://stackoverflow.com/questions/17687429/why-array-type-object-is-not-modifiable/17691191#17691191\">here.

Read this paper (especially the section titled "Embryonic C") for some background; I also have a more detailed answer here.



1。随着Perl或PHP可能是个例外 2 ,最露骨的语言WTFs一般是设计还是妥协的结果的事故;大多数语言都没有的有意的设计是愚蠢的。结果
结果
2.我只曳一点点; Perl和PHP是直线上升的混乱。


1. With the possible exception of Perl or PHP2, most blatant language WTFs are generally accidents of design or the result of compromises; most languages aren't deliberately designed to be stupid.

2. I'm only trolling a little bit; Perl and PHP are straight-up messes.

这篇关于什么是为preventing分配数组的理由?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆