I'm creating some sort of frontend for a program. To launch the program I'm using the call CreateProcess()
, which among other things receives a pointer to a STARTUPINFO
structure. To initialize the structure I used to do:
STARTUPINFO startupInfo = {0}; // Or even ''.
startupInfo.cb = sizeof(startupInfo);
When compiling the program with GCC enabling these sets of warnings -Wall -Wextra
it gives me a warning saying that there's a missing initializer pointing to the first line.
warning: missing initializer
warning: (near initialization for 'startupInfo.lpReserved')
So I ended up doing:
STARTUPINFO startupInfo;
memset(&startupInfo, 0, sizeof(startupInfo));
startupInfo.cb = sizeof(startupInfo);
And this way the compiler doesn't give any warning.
The question is, what is the difference between these ways of initializing a structure?
Using the first method, isn't the structure initialized?
Which one would you recommend?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…