tags:

views:

664

answers:

2

In rpc.h, the GUID structure is declared as follows:

typedef struct _GUID 
{  
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   BYTE Data4[8];
} GUID;

I understand Data1, Data2, and Data3. They define the first, second, and third sets of hex digits when writing out a GUID (XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXX).

What I never understood was why the last 2 groups were declared together in the same byte array. Wouldn't this have made more sense (and been easier to code against)?

typedef struct _GUID 
{  
   DWORD Data1;  
   WORD Data2;  
   WORD Data3;  
   WORD Data4;  
   BYTE Data4[6]; 
} GUID;

Anyone know why it is declared this way?

+3  A: 

http://en.wikipedia.org/wiki/Globally_Unique_Identifier and http://www.opengroup.org/onlinepubs/9629399/apdxa.htm (DCE's orginal representation, you can see the grouping of bits there in a table)

PW
+5  A: 

It's because a GUID is a special case of a UUID. For information on what all the fields mean, you can look at RFC 4122.

Larry Osterman