Why is char[][] = {{…}, {…}} not possible if explicitly given a multidimensional array?

后端 未结 5 1819
灰色年华
灰色年华 2020-12-05 18:30

I went through this article. I understand the rules explained but I am wondering what exactly blocks the compiler from accepting the following syntax when defining a constan

5条回答
  •  一向
    一向 (楼主)
    2020-12-05 18:43

    To briefly expand on the comment:

    What "blocks" the compiler is adherence to the standard (for C or C++, they're different standards, pick one).

    What "blocks" the standard from allowing this is no-one wrote a standards proposal for implementing it which was subsequently accepted.

    So, all you're asking is why no-one was motivated to do something you feel would be useful, and I can only see that as opinion-based.

    There may also be practical difficulties implementing this, or keeping consistent semantics; that's not precisely the question you asked, but it might at least be objectively answerable. I suspect someone could work through those difficulties if sufficiently motivated. Presumably no-one was.

    For example, (reference), the syntax a[] really means array of unknown bound. Because the bound can be inferred in the special case when it's declared using aggregate initialization, you're treating it as something like a[auto]. Maybe that would be a better proposal, since it doesn't have the historical baggage. Feel free to write it up yourself if you think the benefits justify the effort.

提交回复
热议问题