What's the rationale for preventing assignment to arrays?

后端 未结 6 430
抹茶落季
抹茶落季 2020-12-18 17:57

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
6条回答
  •  臣服心动
    2020-12-18 18:29

    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.

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


    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.

提交回复
热议问题