C:为什么我不能用大括号初始化数组内的结构?

时间:2017-11-04 16:37:00

标签: c

我有以下代码:

struct coord {
    float x;
    float y;
};

struct coord vertices[4];

但是当我执行以下操作时,会发生错误:

void setVertices(float x, float y) {
    vertices[0] = (struct coord) { x, y };
}

为什么C中不允许这样做?还有另一种方法吗?谢谢。

1 个答案:

答案 0 :(得分:0)

实际上,我可以通过这种方式初始化结构。由于某种原因,IDE只是滞后于几分钟的错误检查。