delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/01/31/19:06:30

From: Jason Green <news AT jgreen4 DOT fsnet DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Windows ME and DJGPP
Date: Wed, 31 Jan 2001 22:58:56 +0000
Organization: Customer of Energis Squared
Lines: 48
Message-ID: <hd3h7t8mj9s6ijjij6bjd7vokshe4gcvel@4ax.com>
References: <Pine DOT SUN DOT 3 DOT 91 DOT 1010131101046 DOT 29266K-100000 AT is> <3a78130f DOT 16030234 AT news DOT freeserve DOT net>
NNTP-Posting-Host: modem-206.cesium.dialup.pol.co.uk
Mime-Version: 1.0
X-Trace: newsg1.svr.pol.co.uk 980981944 24821 62.136.46.206 (31 Jan 2001 22:59:04 GMT)
NNTP-Posting-Date: 31 Jan 2001 22:59:04 GMT
X-Complaints-To: abuse AT theplanet DOT net
X-Newsreader: Forte Agent 1.7/32.534
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

dontmailme AT iname DOT com (Steamer) wrote:

> Eli Zaretskii wrote:

> > Hmm?  Is this in C or in C++?  I don't think you need any casts in a C
> > program for assigning int to a double or the other way around.
> 
> Nor do you in C++.  It's strange that GCC chooses to warn about
> this in C++ but not in C.

Even stranger when you consider that it does so without even *any*
-W... switches.  Unless, that is, you are of the opinion that this is
an "obviously dangerous conversion" - [BS; CPL3].

Apart from the obvious problem that the value will be truncated to an
integer, there is also undefined behaviour when the integer value is
outside the range of an int.  Of course, an explicit conversion says
to gcc: Yes! I really wanted to do that, and the warning goes away:

float f = 1.2;
int i = int(f);

> > > Compiling: x.cpp
> > > In function `double intconv<double>(double>':
> > > x.cpp (9) Error: instantiated from here
> 
> (Of course, this isn't an error, it's just a RHIDE misinterpretation
> of a warning message, which was what Rudolf Polzer was pointing out.
> I thought this was fixed in newer versions of RHIDE.)

This would surely cause problems when using a severe set of warnings,
but everyone aims to get a clean compile with -Wall, right? ;-)

> > > x.cpp (3) Warning:  initialization to `int' from `double'
> > 
> > If you don't like strongly typed languages, don't use C++.

And if you do like strongly typed languages, don't use C. ;-)

> Some people consider C++ to be a weakly typed language.
> It depends on your perspective...
> 
> In any case, C++ is only slightly more strongly typed than C,
> and there is no difference at all as far as initializing an int
> with a double is concerned.

I guess gcc and g++ view implicit conversions from a different
perspective.

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019