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

Prevent warning: assignment to 'int' from 'double'

P: n/a
I have the following statements

int page.x = page.x * ppiScr.x / 25.4;
int page.y = page.y * ppiScr.y / 25.4;

While VC++ is happy GCC complains the above warning. How can I get rid
of these warnings?

O. Wyss

--
See "http://wxguide.sourceforge.net/" for ideas how to design your app.
Jul 19 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Otto Wyss wrote:
I have the following statements

int page.x = page.x * ppiScr.x / 25.4;
int page.y = page.y * ppiScr.y / 25.4;

While VC++ is happy GCC complains the above warning. How can I get rid
of these warnings?

O. Wyss


Your 25.4 is a double! So the compiler uses the / operator for double and so
the result is double! If you want to assign a double to an int there is an
certain amount of data loss(everthing behind the ,). More advanced
compilers warn you about such things. The program should compile anyway!
If want to get rid of the warning(and make the statement more understandable
for others) you have to cast it!

int page.x = (int) (page.x * (ppiScr.x / 25.4));
or
int page.x = static_cast<int> (page.x * (ppiScr.x / 25.4));

besides are you shure that you want to use
int page.x = page.x * ppiScr.x / 25.4;
you are initializing an page.x with page.x * ...
page.x doesn't have any value yet so page.x * ... could be pretty much
anything!

Hope I could help!
DevH
Jul 19 '05 #2

P: n/a

"Otto Wyss" <wy*@users.sourceforge.net> wrote in message
news:1fzykdf.qko6vt1x1d1dvN%wy*@users.sourceforge. net...
I have the following statements

int page.x = page.x * ppiScr.x / 25.4;
int page.y = page.y * ppiScr.y / 25.4;


That shouldn't compile at all. You are defining "int page.x", and you
should get a syntax error ("; expected") where that period is.
-Howard

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.