C

Asked • 06/20/19

How to initialize a struct in accordance with C programming language standards?

I want to initialize a struct element, split in declaration and initialization. This is what I have: typedef struct MY_TYPE { bool flag; short int value; double stuff; } MY_TYPE; void function(void) { MY_TYPE a; ... a = { true, 15, 0.123 } }Is this the way to declare and initialize a local variable of `MY_TYPE` in accordance with C programming language standards (C89, C90, C99, C11, etc.)? Or is there anything better or at least working?**Update** I ended up having a static initialization element where I set every subelement according to my needs.

1 Expert Answer

By:

Patrick B. answered • 06/20/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.