why there still generates warning?

A

asdf

for (int k=static_cast<int>(box_.min_z());
k<=static_cast<int>(box_.max_z()); k++)

warning: converting
to `int' from `double'


thanks.
 
H

Howard

asdf said:
for (int k=static_cast<int>(box_.min_z());
k<=static_cast<int>(box_.max_z()); k++)

warning: converting
to `int' from `double'

I don't see anything converting from int to double there. I don't even see
anything that's a double, unless it's the return value of max_z() or
min_z(). But you're casting those TO int, not from int to double.

Perhaps the warning is on a different (but nearby) line of code?

-Howard
 
F

Frederick Gotham

asdf posted:
warning: converting
to `int' from `double'


There's a few things you can try to supress the warning.

int i = (int)56.33;

int i = static_cast<int>(56.33);

int i = reinterpret_cast<int>(56.33);

(I'm not 100% sure if you can use reinterpret_cast for this purpose... ?)
 
H

Howard

Howard said:
I don't see anything converting from int to double there. I don't even
see anything that's a double, unless it's the return value of max_z() or
min_z(). But you're casting those TO int, not from int to double.

My mistake. I misread. (It's wierd to phrase it like that, don't you
think... "to int from double"? Most people speak the opposite way: "from A
to B".)

Never mind.

-Howard
 
H

Howard

Frederick Gotham said:
asdf posted:



There's a few things you can try to supress the warning.

int i = (int)56.33;

int i = static_cast<int>(56.33);

That's exactly what the OP tried. (See the code you snipped.) And he still
got the warning. Which I'm assuming is why the subject line was "why there
STILL generates warning?" [emphasis added]

If I substitute my own double values for those min and max functions, I
don't get any such warning. I'm still wondering if the warning isn't on a
different, nearby line of code.

-Howard
 
A

Andrey Tarasevich

Frederick said:
...
int i = reinterpret_cast<int>(56.33);

(I'm not 100% sure if you can use reinterpret_cast for this purpose... ?)
...

No, it can't be used for this purpose. 'reinterpret_cast' is limited to
pointer<->pointer, reference<->reference and pointer<->integer conversions.
 
D

Diego Martins

Andrey said:
No, it can't be used for this purpose. 'reinterpret_cast' is limited to
pointer<->pointer, reference<->reference and pointer<->integer conversions.

are you sure? I thought reinterpret_cast<> can be used in any way, but
the user must face its implementation defined consequences
 
A

Andrey Tarasevich

Diego said:
are you sure? I thought reinterpret_cast<> can be used in any way, but
the user must face its implementation defined consequences
...

No, it can't be. 5.2.10/1 clearly lists the kinds of conversions that can be
performed with 'reinterpret_cast' and states that "no other conversion can be
performed" using it.
 

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,755
Messages
2,569,534
Members
45,007
Latest member
obedient dusk

Latest Threads

Top