views:

427

answers:

2

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?

+2  A: 

Using the standard c library:

GUID myGuid;
memset(&myGuid, 0, sizeof(GUID));

Or the more microsoft-style way:

GUID myGuid;
ZeroMemory(&myGuid, sizeof(GUID));
Emil H
+4  A: 
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.

sharptooth