Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initializing a GUID variable

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?

like image 319
Bharani Avatar asked Aug 06 '26 16:08

Bharani


2 Answers

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.

like image 155
sharptooth Avatar answered Aug 09 '26 01:08

sharptooth


Using the standard c library:

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

Or the more microsoft-style way:

GUID myGuid;
ZeroMemory(&myGuid, sizeof(GUID));
like image 24
Emil H Avatar answered Aug 09 '26 00:08

Emil H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!