I am using VC++ 6.0 on Windows XP SP2 platform. I am using GUID structure in my code.
typedef struct _GUID { // size is 16
DWORD Data1;
WORD Data2;
WORD Data3;
BYTE Data4[8];
} GUID;
How to initialize this structure to zeros while creating an object? Or when I create an object, what is the default value for the members?
GUID newId = GUID_NULL;
If you don't do it the fields are uninitialized and contain whatever data was in memory at that location - it's typical to call that garbage.
Using the standard c library:
GUID myGuid;
memset(&myGuid, 0, sizeof(GUID));
Or the more microsoft-style way:
GUID myGuid;
ZeroMemory(&myGuid, sizeof(GUID));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With