In (ANSI) C99, you can use a designated initializer to initialize a structure:
MY_TYPE a = { .flag = true, .value = 123, .stuff = 0.456 };
Other members are initialized as zero: “Omitted field members are implicitly initialized the same as objects that have static storage duration.” (https://gcc.gnu.org/onlinedocs/gcc/Designated-Inits.html)
Related Posts:
- typedef struct vs struct definitions [duplicate]
- Why should we typedef a struct so often in C?
- Why should we typedef a struct so often in C?
- typedef struct vs struct definitions [duplicate]
- dereferencing pointer to incomplete type
- “error: assignment to expression with array type error” when I assign a struct field (C)
- Error “initializer element is not constant” when trying to initialize variable with const
- How do you make an array of structs in C?
- Difference between a Structure and a Union
- Incompatible implicit declaration of built-in function ‘malloc’
- How can I use an array of function pointers?
- What is the cause of flexible array member not at end of struct error?
- size of struct in C
- Why am I getting this error: “data definition has no type or storage class”?
- Scanning Multiple inputs from one line using scanf
- Initializing array of structures
- typedef struct pointer definition
- Constructor for structs in C
- The difference between n++ and ++n at the end of a while loop? (ANSI C)
- Working on code to calculate cosine with factorial sum
- warning: implicit declaration of function
- What exactly is the difference between “pass by reference” in C and in C++?
- What does “collect2: error: ld returned 1 exit status” mean?
- How to convert an int to string in C?
- Floating point exception (core dumped)
- what is the difference between uint16_t and unsigned short int incase of 64 bit processor?
- Correct format specifier for double in printf
- How to convert a string to integer in C?
- What is the behavior of integer division?
- Awesomium sdk download
- Bad File Descriptor with Linux Socket write() Bad File Descriptor C
- What is the difference between char s[] and char *s?
- Reading from file using read() function
- What is the difference between ++i and i++?
- warning: assignment makes integer from pointer without a cast
- munmap_chunk(): invalid pointer
- printf() formatting for hexadecimal
- The importance of c enumeration (typedef enum) [duplicate]
- Cannot assign requested address – possible causes?
- need help understanding the movzbl call in this function
- What is the difference between read and pread in unix?
- What does “control reaches end of non-void function” mean?
- connect Error: “No route to host”
- warning: implicit declaration of function
- C dynamically growing array
- How to replicate vector in c?
- Why do I get an assertion failure?
- Difference between int32, int, int32_t, int8 and int8_t
- C compile error: “Variable-sized object may not be initialized”
- What does WEXITSTATUS(status) return?
- Xcode – Warning: Implicit declaration of function is invalid in C99
- Error: control may reach end of non-void function in C
- C language: float % float why expression must have integral type
- lvalue required as left operand of assignment
- how to convert negative hexadecimal to decimal
- Why am I getting “undefined reference to sqrt” error even though I inclu de math.h header?
- In C, how should I read a text file and print all strings
- What does “Size in TCHARs” means?
- What’s the difference between a file descriptor and file pointer?
- return makes integer from pointer without a cast [-Wint-conversion] return candidate
- Math constant PI value in C
- Cygwin – Makefile-error: recipe for target `main.o’ failed
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Why am I getting “undefined reference to sqrt” error even though I include math.h header?
- Expected declaration specifier error in function
- When and why to use malloc?
- Multiple definition of … linker error
- C compile error: Id returned 1 exit status
- How do I concatenate const/literal strings in C?
- Efficient way to find task_struct by pid
- Why am I getting this memory access error ‘double free or corruption’?
- How can one print a size_t variable portably using the printf family?
- How to make sense of modulo in c
- Memory Clobbering Error
- “No such file or directory” error in CodeBlocks
- Uninitialized value was created by a heap allocation
- Makefile:1: *** missing separator. Stop
- double free or corruption (!prev) error in c program
- xorl %eax – Instruction set architecture in IA-32
- What does this GCC error “… relocation truncated to fit…” mean?
- Two or more data types in declaration specifiers error
- ‘sprintf’: double precision in C
- C printing bits
- How do I find the time complexity (Big O) of while loop?
- Why do we use NULL in strtok()?
- C Unknown type name ‘my_structure’
- PTHREAD_MUTEX_INITIALIZER vs pthread_mutex_init ( &mutex, param)
- How to concatenate string and int in C?
- execvp: bad address error
- How detect malloc failure?
- A Simple, 2d cross-platform graphics library for c or c++?
- Removing last character in C
- error: ISO C forbids nested functions – What’s wrong?
- Dereference void pointer
- Use of flag in c?
- Carriage return in C?
- Why and when to use static structures in C programming?
- Difference between “while” loop and “do while” loop
- Swapping 2 Bytes of Integer
- GDB no such file or directory