By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,351 Members | 1,239 Online
Bytes IT Community
+ Ask a Question
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 <winnt.h>.
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
Share this Question
Share on Google+
13 Replies


P: n/a
Lamefif wrote:
// The GUID is represented as a structure defined in <winnt.h>.
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 <winnt.h>.
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" <v.Abaza...@comAcast.netwrote:
Lamefif wrote:
// The GUID is represented as a structure defined in <winnt.h>.
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" <v.Abaza...@comAcast.netwrote:
>Lamefif wrote:
>>// The GUID is represented as a structure defined in <winnt.h>.
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" <v.Abaza...@comAcast.netwrote:
>Lamefif wrote:
// The GUID is represented as a structure defined in <winnt.h>.
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
Sep 14 '07 #6

P: n/a
On Sep 14, 3:42 pm, Erik Wikström <Erik-wikst...@telia.comwrote:
On 2007-09-14 16:24, Lamefif wrote:
On Sep 14, 2:57 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Lamefif wrote:
// The GUID is represented as a structure defined in <winnt.h>.
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:
[..]
pardon my ignorance.
No problem at all (although I suspect that you're being sarcastic).
a char memory cell would be the address and 8 bit char value, and we
have 8 of these.
A memory cell is not the address. It _has_ an address.
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 memory blocks,
each contains 1 char (byte). 'Data4' is a variable name, no less 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 memory blocks
stringed together? That's just the C++ magic, man.
is the computer putting aside a chunk made up of 8 cells and assigning
to this collective a single address (Data4)?
Here you go, using the "a" word again... 'Data4' is an item in your
source code. If you ask for its address, the address of the first
element in the array (the type of 'Data4') is given (and, yes, all
other 7 elements follow the first one closely).
i mean these are 8 separate bytes each with they're own address right,
Right.
you cannot bug em up
I don't know what that means.
i would appreciate a bit more then "It needs a careful consideration
to be understood"
I meant the fact that 'Data4' _name_ used in an expression is converted
to a pointer requires some understanding. I did not mean the allocation
of the characters in the memory or the addressing methods used by the
compiler.

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 #8

P: n/a
On Sep 14, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Lamefif wrote:
[..]
pardon my ignorance.

No problem at all (although I suspect that you're being sarcastic).
Not at all
>
a char memory cell would be the address and 8 bit char value, and we
have 8 of these.

A memory cell is not the address. It _has_ an address.
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 memory blocks,
each contains 1 char (byte). 'Data4' is a variable name, no less 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 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?
>
is the computer putting aside a chunk made up of 8 cells and assigning
to this collective a single address (Data4)?

Here you go, using the "a" word again... 'Data4' is an item in your
source code. If you ask for its address, the address of the first
element in the array (the type of 'Data4') is given (and, yes, all
other 7 elements follow the first one closely).
exactly it cant possibly know where the next char is, apart form the
fact that they are next to each other and we can increment.
is only aware of the first element, the one is pointing to ?
>
i mean these are 8 separate bytes each with they're own address right,

Right.
you cannot bug em up

I don't know what that means.
sorry i meant bag em up
>
i would appreciate a bit more then "It needs a careful consideration
to be understood"

I meant the fact that 'Data4' _name_ used in an expression is converted
to a pointer requires some understanding. I did not mean the allocation
of the characters in the memory or the addressing methods used by the
compiler.

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 #9

P: n/a
Lamefif wrote:
On Sep 14, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
>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 memory
blocks, each contains 1 char (byte). 'Data4' is a variable name, no
less 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 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
Sep 14 '07 #10

P: n/a
On Sep 14, 6:25 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
Lamefif wrote:
On Sep 14, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
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 memory
blocks, each contains 1 char (byte). 'Data4' is a variable name, no
less 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 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 <Leonardo.Pje...@googlemail.comwrote:
On Sep 14, 5:53 pm, "Victor Bazarov" <v.Abaza...@comAcast.netwrote:
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 memory blocks, each contains 1 char (byte).
'Data4' is a variable name, no less 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 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?
What's so magical about it. If I write "double d;", d is used
to identify a block of 8 bytes. If I write "char a[8];", a is
used to identify a block of 8 bytes. The only real difference
is that in the second case, each of those bytes is individually
accessible, via its own address. (This is actually the case as
well with double, but getting at the individual bytes requires
some advanced programming, using reinterpret_cast, etc.)
is the computer putting aside a chunk made up of 8 cells and assigning
to this collective a single address (Data4)?
Here you go, using the "a" word again... 'Data4' is an item in your
source code. If you ask for its address, the address of the first
element in the array (the type of 'Data4') is given (and, yes, all
other 7 elements follow the first one closely).
exactly it cant possibly know where the next char is, apart
form the fact that they are next to each other and we can
increment. is only aware of the first element, the one is
pointing to ?
What Victor is saying is that:

1. Data4 is the name of a variable with the type char[8]. It's
not the name of any one element of the array, but refers to
the entire array (which is a compound object, like a
structure).

2. In certain contexts (a lot of them, actually), the name
Data4 will convert implicitly to the address of the first
element of the array. And because of the way address
arithmetic works in C++, Data4+1 will then be the address of
the second element, Data4+2 that address of the third, etc.

Note that in 2, there is a conversion. Data4 isn't an address;
it is the name of a variable which contains all 8 elements. It
is only the result of the conversion which is an address, and
whose type is that of a single element.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34

Sep 15 '07 #13

P: n/a
In article <JN****************@newsb.telia.net>, Er***********@telia.com
says...
On 2007-09-14 15:35, Lamefif wrote:
// The GUID is represented as a structure defined in <winnt.h>.
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.