www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/11/20/02:30:03

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: list of djgpp compiler errors wanted!
Date: Tue, 19 Nov 1996 19:35:00 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 53
Message-ID: <32927C64.4CFE@cs.com>
References: <32905cab DOT 10273409 AT news DOT uu DOT se>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp103.cs.com
Mime-Version: 1.0
To: Martin Gumucio <martin DOT gumucio AT mcu DOT uu DOT se>
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Martin Gumucio wrote:
> 
> I'm just learning c++ but djgpp is complaining on my coding...
> 
> this source is copied right out of my book
> 
> int auks;
> auks = 19.99 + 11.99;

Books are not always right.  To be correct, the above code should use a
typecast to int.  If your book was using that as an example of implicit
type demotion, then the warning gcc gave you is correct, isn't it?

To be 100% correct, rewrite your code as one of the following:

int auks;
auks = (int) (19.99 + 11.99);

-or-

double auks;
auks = 19.99 + 11.99;

-or-

int auks;
auks = floor( 19.99 + 11.99 );

> this is the commandline i use
> 
> gxx SAMPLE.CPP  -o SAMPLE.EXE -lm

This is wrong.  Your programs must have lowercase extensions to work
properly with gcc.  Also, you should add -Wall and -O to your command
line to catch more than just the basic problems.

> and this came out of the compiler
> utypomv.cpp: In function `int main()':
> utypomv.cpp:10: warning: assignment to `int' from `double'
> 
> it simply refuses to make me use type casting of any form.

A warning does not prevent your program from compiling.  It will still
compile, and it will probably work, but you should always fix any
warnings your code gives you as soon as you have the chance.

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I  |        fighteer AT cs DOT com         |
|    *  Proud user of DJGPP!  *    |   http://www.cs.com/fighteer   |
|    ObJoke:  If Bill Gates were a robber, not only would he        |
|     shoot you, but he'd send you a bill for the bullets.          |
---------------------------------------------------------------------

- Raw text -


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