473,386 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

no compiler warning for int to double conversion with nocast...strange

The below did not set off my compiler, perhaps because I set the
warnings to a higher (less nag) level.

Strange.

FYI, no question being asked.

RL

double d2030;
float f2030;

int i20 = 20;
int j30 = 30;

f2030 = i20 / j30;

d2030 = i20 / j30; //no cast needed? NO! need cast as shown below
(otherwise you get zero on LHS)

d2030 = (double) i20 / (double)j30; //cast needed as shown, to give
d2030 = 0.666…

// same for f2030, cast needed as above

Oct 31 '08 #1
1 2701
raylopez99 wrote:
The below did not set off my compiler, perhaps because I set the
warnings to a higher (less nag) level.

Strange.
Not Strange.

Assigning an int to a double does not loose any precision.
>double d2030;
float f2030;

int i20 = 20;
int j30 = 30;

f2030 = i20 / j30;

d2030 = i20 / j30; //no cast needed? NO! need cast as shown below
(otherwise you get zero on LHS)

d2030 = (double) i20 / (double)j30; //cast needed as shown, to give
d2030 = 0.666…
RHS is evaluated without considering.

Your problem is with integer division. It is completely
unrelated to the assignment of int to double.

And the compiler never gives warning about an integer division. It
assume that when you do an integer division that is what you meant
to do.

Arne
Nov 1 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: Alf P. Steinbach | last post by:
// As usual the error message directs one to the report the bug. // // And as usual there is absolutely no way to do so without paying for // the privilege... // // Or using three or four hours...
1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
20
by: Markus Sandheide | last post by:
Hello! Execute these lines: int x = 1; x = x > 2345678901; You will get: x == 1 with Borland C++ Builder
8
by: grundmann | last post by:
Hello, i got a strange compiler error. When compiling the following: // forward declarations typedef AvlTree<LineSegment,LineSegmentComperator> LSTree; void handleEventPoint (const...
29
by: junky_fellow | last post by:
Consider the following piece of code: struct junk { int i_val; int i_val1; char c_val; }; int main(void) {
11
by: Henryk | last post by:
I have some very simple code fragment: short int n1, n2; .... n1 += n2; I get an warning from VS2003 - VS2005: warning C4244: '+=' : conversion from 'int' to 'short', possible loss of data ...
3
by: gil | last post by:
Hi, I'm trying to find the best way to work with compiler warnings. I'd like to remove *all* warnings from the code, and playing around with the warning level, I've noticed that compiling with...
5
by: happytoday | last post by:
I compiled that program under turbo C without any problems but with sunstudi I found those errors: "pnt02ma1.c", line 37: warning: implicit function declaration: system "pnt02ma1.c", line 58:...
2
by: Chris Peters | last post by:
Hi, I'm using some Fortran 77 code together with C, and the compiler is giving me some strange warnings. Can anyone help explain what's going on? The code runs just fine. 1) Fortran code
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.