By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,820 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,820 IT Pros & Developers. It's quick & easy.

why there still generates warning?

P: n/a
for (int k=static_cast<int>(box_.min_z());
k<=static_cast<int>(box_.max_z()); k++)

warning: converting
to `int' from `double'
thanks.

Jul 6 '06 #1
Share this Question
Share on Google+
8 Replies


P: n/a
asdf wrote:
for (int k=static_cast<int>(box_.min_z());
k<=static_cast<int>(box_.max_z()); k++)

warning: converting
to `int' from `double'
This is in the FAQ:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.8

Good luck.

Best regards,

Tom

Jul 6 '06 #2

P: n/a

"asdf" <li*********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
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
Jul 6 '06 #3

P: n/a
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... ?)
--

Frederick Gotham
Jul 6 '06 #4

P: n/a

"Howard" <al*****@hotmail.comwrote in message
news:ty*********************@bgtnsc05-news.ops.worldnet.att.net...
>
"asdf" <li*********@gmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
>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.
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

Jul 6 '06 #5

P: n/a

"Frederick Gotham" <fg*******@SPAM.comwrote in message
news:2I*******************@news.indigo.ie...
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);
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

Jul 6 '06 #6

P: n/a
Frederick Gotham wrote:
...
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.

--
Best regards,
Andrey Tarasevich
Jul 7 '06 #7

P: n/a

Andrey Tarasevich wrote:
Frederick Gotham wrote:
...
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.

--
Best regards,
Andrey Tarasevich
are you sure? I thought reinterpret_cast<can be used in any way, but
the user must face its implementation defined consequences

Jul 7 '06 #8

P: n/a
Diego Martins wrote:
Andrey Tarasevich wrote:
>Frederick Gotham wrote:
...
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.

--
Best regards,
Andrey Tarasevich

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.

--
Best regards,
Andrey Tarasevich
Jul 7 '06 #9

This discussion thread is closed

Replies have been disabled for this discussion.