I saw this in some C code:
Wininfo W = { sizeof(Wininfo) };
What the heck does this mean?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
This code is initializing a
structusing funky C initializer syntax to initialize each field in order of declaration, see http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=421. An important side-effect in the case of this example is that remaining fields one doesnt specify values for get initialized to zeros.This trick is a relatively common one in Win32 APIs – the API requires the size to be pre-set as a way of indicating the version the client code is compiled against – in many of these cases, one is also expected to clear the buffer, which would ordinarily involve a separate call to e.g.
memsetprior to initializing the size field with thesizeof.See also Struct initialization of the C/C++ programming language? for related examples