how to assign multiple values into a struct at once?

前端 未结 6 1932
执笔经年
执笔经年 2020-12-02 13:15

I can do this on initialization for a struct Foo:

Foo foo =  {bunch, of, things, initialized};

but, I can\'t do this:

Foo f         


        
6条回答
  •  萌比男神i
    2020-12-02 13:47

    Try this:

    Foo foo;
    foo = (Foo){bunch, of, things, initialized};
    

    This will work if you have a good compiler (e.g. GCC). You might need to turn on C99 mode with --std=gnu99, I'm not sure.

提交回复
热议问题