简体   繁体   中英

C: Why can I not initialize structs inside of arrays with curly brackets?

I have the following code:

struct coord {
    float x;
    float y;
};

struct coord vertices[4];

But when I do the following, an error occurs:

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

Why isn't this allowed in C? Is there another way to do this? Thank you.

I can initialize structs that way, actually. The IDE just lagged on its error-checking for several minutes, for some reason.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM