4
440gtx
I frequently interface with API's that require one to "clear out" a
POD structure (some people choose memset or equivalent for this), then
fill in a set of relevant fields based on the type of function call
the struct is being used for. Would method (a) or (b) below be more
appropriate and will there be a difference technically speaking,
keeping in mind this is POD? I also included a third method (c)
wondering if it is good practice or not for cases where the structure
begins with a field that needs initialized with the size of the
structure:
API_STRUC a = {0};
API_STRUC b = {};
API_STRUC c = {sizeof c};
....fill in a few fields...
api_func(&a); // or b or c
So anyway which would you use (a, b, c), if any, and why?
POD structure (some people choose memset or equivalent for this), then
fill in a set of relevant fields based on the type of function call
the struct is being used for. Would method (a) or (b) below be more
appropriate and will there be a difference technically speaking,
keeping in mind this is POD? I also included a third method (c)
wondering if it is good practice or not for cases where the structure
begins with a field that needs initialized with the size of the
structure:
API_STRUC a = {0};
API_STRUC b = {};
API_STRUC c = {sizeof c};
....fill in a few fields...
api_func(&a); // or b or c
So anyway which would you use (a, b, c), if any, and why?