449,351 Members | 1,239 Online
Need help? Post your question and get tips & solutions from a community of 449,351 IT Pros & Developers. It's quick & easy.

# understanding GUID

 P: n/a // The GUID is represented as a structure defined in . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to an array longer then 32 bits(8 char * 8 bits = 64), which would make a GUID bigger then 128 bits? is Data4 a pointer, are they usually not 4 bits? Sep 14 '07 #1
13 Replies

 P: n/a Lamefif wrote: // The GUID is represented as a structure defined in . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? On a system with specific sizes of 'short' and 'char', probably. but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to an array longer then 32 bits(8 char * 8 bits = 64), Uh... How could it be both? In the first sentence you said "Data4 is an *array* " (emphasis mine), and in the second you said "Data4 is a pointer". AFAICS, it's an array. which would make a GUID bigger then 128 bits? Why? Suppose 'long' is 32 bits, 'short' is 16 bits, and 'char' is 8 bits. Suppose there is no padding. 32 + 16 + 16 + 8*8 =128. is Data4 a pointer, are they usually not 4 bits? Data4 is NOT a pointer. It's an array. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Sep 14 '07 #2

 P: n/a On 2007-09-14 15:35, Lamefif wrote: // The GUID is represented as a structure defined in . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? but looking at the structure, i have some questions. No, GUID is a data-structure which might take 128 bits of memory, it is not a 128 bit number. -- Erik Wikström Sep 14 '07 #3

 P: n/a On Sep 14, 2:57 pm, "Victor Bazarov" . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? On a system with specific sizes of 'short' and 'char', probably. but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to an array longer then 32 bits(8 char * 8 bits = 64), Uh... How could it be both? In the first sentence you said "Data4 is an *array* " (emphasis mine), and in the second you said "Data4 is a pointer". AFAICS, it's an array. which would make a GUID bigger then 128 bits? Why? Suppose 'long' is 32 bits, 'short' is 16 bits, and 'char' is 8 bits. Suppose there is no padding. 32 + 16 + 16 + 8*8 =128. is Data4 a pointer, are they usually not 4 bits? Data4 is NOT a pointer. It's an array. Thanks Victor. Data4 is a variable that holds the address of the first char, No?. In other words we would need space for Data4 as well as 8 chars? Sep 14 '07 #4

 P: n/a Lamefif wrote: On Sep 14, 2:57 pm, "Victor Bazarov" Lamefif wrote: >>// The GUID is represented as a structure defined in .typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; [..] Data4 is a variable that holds the address of the first char, No?. No. In other words we would need space for Data4 as well as 8 chars? No. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Sep 14 '07 #5

 P: n/a On 2007-09-14 16:24, Lamefif wrote: On Sep 14, 2:57 pm, "Victor Bazarov" Lamefif wrote: // The GUID is represented as a structure defined in . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? On a system with specific sizes of 'short' and 'char', probably. but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to an array longer then 32 bits(8 char * 8 bits = 64), Uh... How could it be both? In the first sentence you said "Data4is an *array* " (emphasis mine), and in the second you said "Data4 isa pointer". AFAICS, it's an array. which would make a GUID bigger then 128 bits? Why? Suppose 'long' is 32 bits, 'short' is 16 bits, and 'char' is 8bits. Suppose there is no padding. 32 + 16 + 16 + 8*8 =128. is Data4 a pointer, are they usually not 4 bits? Data4 is NOT a pointer. It's an array. Thanks Victor. Data4 is a variable that holds the address of the first char, No?. No, that would be a pointer. Data4 is an array of 8 chars, in other words 8 chars placed one after another in memory. -- Erik Wikström Sep 14 '07 #6

 P: n/a On Sep 14, 3:42 pm, Erik Wikström . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? On a system with specific sizes of 'short' and 'char', probably. but looking at the structure, i have some questions. Data4 is an array of char of length 8. meaning Data4 is a pointer to an array longer then 32 bits(8 char * 8 bits = 64), Uh... How could it be both? In the first sentence you said "Data4 is an *array* " (emphasis mine), and in the second you said "Data4 is a pointer". AFAICS, it's an array. which would make a GUID bigger then 128 bits? Why? Suppose 'long' is 32 bits, 'short' is 16 bits, and 'char' is 8 bits. Suppose there is no padding. 32 + 16 + 16 + 8*8 =128. is Data4 a pointer, are they usually not 4 bits? Data4 is NOT a pointer. It's an array. Thanks Victor. Data4 is a variable that holds the address of the first char, No?. No, that would be a pointer. Data4 is an array of 8 chars, in other words 8 chars placed one after another in memory. -- Erik Wikström ^ thanks i think i got it :) Data4 holds the first char. Sep 14 '07 #7

 P: n/a Lamefif wrote: On Sep 14, 5:53 pm, "Victor Bazarov" Lamefif wrote: >>[..]you are saying that Data4 holds all 8 cells. Yes. The type of 'Data4' is "an array of 8 chars". That means that'Data4' designates the area in memory that consists of 8 memoryblocks, each contains 1 char (byte). 'Data4' is a variable name, noless but no more. >>how is this done? How what is done? How 8 consecutive memory blocks are allocated?How one variable can be used to identify a whole bunch of memoryblocks stringed together? That's just the C++ magic, man. yes that the magic, how one variable can be used to identify a bunch of memory blocks? I am not sure what it is you want to know. How does a function identify a whole lot of operations performed by the CPU on the data passed to it or otherwise available for manipulation? Forget that, how can *one* variable be used to identify a _single_ memory block? If you can answer (if you understand) the latter, what is the problem of understanding the arrays? (BTW, what book are you reading that doesn't explain arrays?) An array is an object that consists of other objects, called "elements", and in which those elements are placed contiguously in the memory given to the array itself. In a system where 'sizeof(int) != 1', how does an object of type 'int' identify a bunch of bytes? From the language point of view it really does not matter. Magic. Electronics. Logic. The compiler/system/CPU all work do make it transparent to the user or programmer. If you want to know the object model of C++, find and read "Inside the C++ Object Model" by Stanley Lippman. But you don't have to actually understand all this to be a successful C++ programmer. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Sep 14 '07 #10

 P: n/a On Sep 14, 6:25 pm, "Victor Bazarov" how is this done? How what is done? How 8 consecutive memory blocks are allocated? How one variable can be used to identify a whole bunch of memory blocks stringed together? That's just the C++ magic, man. yes that the magic, how one variable can be used to identify a bunch of memory blocks? I am not sure what it is you want to know. How does a function identify a whole lot of operations performed by the CPU on the data passed to it or otherwise available for manipulation? Forget that, how can *one* variable be used to identify a _single_ memory block? If you can answer (if you understand) the latter, what is the problem of understanding the arrays? (BTW, what book are you reading that doesn't explain arrays?) An array is an object that consists of other objects, called "elements", and in which those elements are placed contiguously in the memory given to the array itself. In a system where 'sizeof(int) != 1', how does an object of type 'int' identify a bunch of bytes? From the language point of view it really does not matter. Magic. Electronics. Logic. The compiler/system/CPU all work do make it transparent to the user or programmer. If you want to know the object model of C++, find and read "Inside the C++ Object Model" by Stanley Lippman. But you don't have to actually understand all this to be a successful C++ programmer. V -- Please remove capital 'A's when replying by e-mail I do not respond to top-posted replies, please don't ask Thanks for the book suggestion i will have a look at it ...downloading now :) Sep 14 '07 #11

 P: n/a Lamefif wrote: you are saying that Data4 holds all 8 cells. how is this done? is the computer putting aside a chunk made up of 8 cells and assigning to this collective a single address (Data4)? You seem to think that Data4 is a variable holding something (eg. an address to the array). It isn't. Data4 is just a C++ symbol which can be used to refer to the array it symbolizes. For example, if you perform a sizeof(Data4) what C++ will do is to look the size of that array and return it. It won't return the size of "Data4" because it's not a variable, it's just a name symbolizing that array. You might be confused by the fact that C++ defines some implicit "conversions" from an array symbol to a pointer. For example, if a pointer is expected and you give it the array symbol, an implicit "conversion" will be performed, and a pointer to the first item in the array will be the result. This doesn't mean that Data4 is a pointer (because it isn't, eg. sizeof(Data4) is a proof of that). It just means that a pointer pointing to the first item of the array symbolized by Data4 will be created as necessary. This is a C++ source code construct. It has basically nothing to do with how the CPU and its memory works. 'Data4' is an abstract symbol. It doesn't contain anything. It just can be used, in C++, to refer to the array (and eg. create pointers pointing to it). Sep 14 '07 #12

 P: n/a On Sep 14, 7:13 pm, Lamefif

 P: n/a In article , Er***********@telia.com says... On 2007-09-14 15:35, Lamefif wrote: // The GUID is represented as a structure defined in . typedef struct_GUID{ unsigned long Data1; unsigned short Data2; unsigned short Data3; unsigned char Data4[8];} GUID; GUID is a 128-bit number ? but looking at the structure, i have some questions. No, GUID is a data-structure which might take 128 bits of memory, it is not a 128 bit number. Actually, you have things sort of backwards: a GUID _is_ a 128-bit number, and this structure is only a valid representation of a GUID on an implementation that assures the struct occupies exactly 128 bits. In case that wasn't clear, a GUID is a concept that exists entirely separately from C++ or this struct. This struct is simply one possible way of storing a GUID. -- Later, Jerry. The universe is a figment of its own imagination. Sep 15 '07 #14

### This discussion thread is closed

Replies have been disabled for this discussion.