How can I declare and initialize the structure in a different place?
For example, in this code,
typedef struct MY_TYPE {
boolean flag;
short int value;
double stuff;
} } MY_TYPE;
void function(void) {
MY_TYPE a;
...
a = { true, 15, 0.123} // Like this
}
How do I initialize a member variable within MY_TYPE in ANSI C (C89, C90, C99, C11 etc.)?
If you want to separate declaration and initialization,
a.flag = true;
a.values = 15;
Is there no choice but to designate everything like this?
c struct initialization
At ANSI C99,
MY_TYPE a = { .flag = true, .value = 123, .stuff = 0.456 };
A variable that can be written together and that you do not specify is initialized to zero.
This is called designated initializer.
For more information, see Designed Initiators.
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
613 GDB gets version error when attempting to debug with the Presense SDK (IDE)
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
916 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
© 2024 OneMinuteCode. All rights reserved.