What does this mean?

J

JoeC

m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;

What does this mean?

I have seen v=&var->member.thing;

but what does it mean when you change the & for int?
 
V

Victor Bazarov

JoeC said:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;

What does this mean?

I have seen v=&var->member.thing;

but what does it mean when you change the & for int?

You don't change anythign for anything. The unary operator & is
for taking the address of the operand. The (blah) notation is
for *casting* the left operand into a different type. Look it up
in your favourite C++ book (BTW, which one are you reading that
doesn't describe those?)

V
 
L

LR

JoeC said:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;

What does this mean?

I have seen v=&var->member.thing;

but what does it mean when you change the & for int?



v=&var->member.thing; means that v is going to get the address of
var->member.thing.

&'s precedence is lower than both -> and .
Think of it as:
v = &(var->member.thing)

v must be a pointer to whatever type var->member.thing is.

The change you are asking about wouldn't be all, because the type of v
would have to change too.

If this compiles:
int *v = &var->member.thing;
this of course won't:
int *v = (int)var->member.thing;
but this will:
int v = (int)var->member.thing;



http://en.wikipedia.org/wiki/Operators_in_C_and_C++

LR
 
O

Old Wolf

The unary operator & is
for taking the address of the operand. The (blah) notation is
for *casting* the left operand into a different type.

The (int) casts what's to the right of it (I'm sure
you know this, but you wrote 'left operand').

Also, in this example it casts the entirety of the
right-hand side of the '=', since -> and . bind
more tightly than the cast.
 
J

Jim Langston

JoeC said:
m_iWidth = (int)pBitmapInfo->bmiHeader.biWidth;
m_iHeight = (int)pBitmapInfo->bmiHeader.biHeight;

What does this mean?

I have seen v=&var->member.thing;

but what does it mean when you change the & for int?

To restate what Victor said,

(int) is a "c style cast". In C++ we could use that or the safer, prefered
static_cast<int>.
& is "address of"
* is "contents of" (also called dereferencing).

A cast will convert one type to another. A static cast generally is used to
covert the value of one type to another. Say, for instance, biWidth was a
double. The (int) says to convert it to an integer.
 
V

Victor Bazarov

Old said:
The (int) casts what's to the right of it (I'm sure
you know this, but you wrote 'left operand').

It was a braino, I was thinking that both operators are written
to the left of what they operate on... Thanks for noticing and
correcting.
Also, in this example it casts the entirety of the
right-hand side of the '=', since -> and . bind
more tightly than the cast.

I am guesing you use the terms "bind more tightly" in place of
"have higher precedence".

V
 
B

BobR

Jim Langston wrote in message...
in message...

To restate what Victor said,

(int) is a "c style cast". In C++ we could use that or the safer, prefered
static_cast<int>.
& is "address of"
* is "contents of" (also called dereferencing).

A cast will convert one type to another. A static cast generally is used to
covert the value of one type to another. Say, for instance, biWidth was a
double. The (int) says to convert it to an integer.

Also:
// C style cast
m_iWidth = (int) pBitmapInfo->bmiHeader.biWidth;

// C++ style (conversion. watch your compile 'warnings'.)
m_iWidth = int( pBitmapInfo->bmiHeader.biWidth );
 
J

JoeC

You don't change anythign for anything. The unary operator & is
for taking the address of the operand. The (blah) notation is
for *casting* the left operand into a different type. Look it up
in your favourite C++ book (BTW, which one are you reading that
doesn't describe those?)
What I mean is that where the (int) is there is a&. That is I can get
data from a pointer but what does the (int) or the type in () mean?
 
J

JoeC

v=&var->member.thing; means that v is going to get the address of
var->member.thing.

&'s precedence is lower than both -> and .
Think of it as:
v = &(var->member.thing)

v must be a pointer to whatever type var->member.thing is.

The change you are asking about wouldn't be all, because the type of v
would have to change too.

If this compiles:
int *v = &var->member.thing;
this of course won't:
int *v = (int)var->member.thing;
but this will:
int v = (int)var->member.thing;

http://en.wikipedia.org/wiki/Operators_in_C_and_C++

LR

Thanks, it makes sense now.
 
B

BobR

JoeC wrote in message...
What I mean is that where the (int) is there is a&. That is I can get
data from a pointer but what does the (int) or the type in () mean?
It's a 'cast'. Remove it and re-compile. Does the compiler complain?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,279
Latest member
LaRoseDermaBottle

Latest Threads

Top