7 Replies - 737 Views - Last Post: 09 February 2012 - 04:40 PM Rate Topic: -----

#1 Bryston  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 125
  • Joined: 24-January 12

The evils of DevC++

Posted 09 February 2012 - 02:43 PM

Like many beginners I downloaded DevC++ and started bashing away.
It was pointed out by many people that getting a new compiler was pretty much required to remain sane.
So, I downloaded code::blocks.
I hadn't actually installed it and was working on a little project to manipulate binary numbers, like convert to decimal, do bitwise operations etc...

here's what happened in DevC++
//some stuff
#include<cmath>
//some more stuff

int bit_value = pow(2, position);

//some more stuff


generated the following error:
58 C:\working\bin2dec.cpp call of overloaded `pow(int, int&)' is ambiguous 



hmmm, odd that, i wonder what happens if i change it a bit to
//some stuff
#include<math.h>
//some more stuff

int bit_value = pow(2, position);

//some more stuff


generated the following warning:
58 C:\working\bin2dec.cpp [Warning] converting to `int' from `double' 



So I installed code::blocks, compiled without warning and program ran fine.

No more DevC++ for this cat.
Stay hip!

Is This A Good Question/Topic? 0
  • +

Replies To: The evils of DevC++

#2 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: The evils of DevC++

Posted 09 February 2012 - 02:56 PM

I'm pretty sure every one of the mods, mentors, experts, etc. on this forum will recommend against using Dev-C++.

However, this one's on you, not Dev-C++.

Your compiler should give you a warning for that code, because the pow function returns a double, float or long double, and not an int. If CodeBlocks isn't giving you a warning it's because you have your Compiler Settings set incorrectly. Go into the menu "Settings/Compiler and Debugger" and check a bunch of boxes saying "Warn if ... " so you will be warned before you get into trouble.

I suggest -Wall, -Wextra -pedantic and -Weffc++ at the very least.
Was This Post Helpful? 0
  • +
  • -

#3 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: The evils of DevC++

Posted 09 February 2012 - 03:06 PM

By the way, you should also understand that compiler warnings aren't the same as compiler error messages. When you get an error message, the code isn't compiled. When you get a warning, the code is compiled and you can run it "at your peril".

Sometimes it's perfectly safe to ignore certain warnings -- as long as you understand the meaning and reason for the warning and are aware of the possible consequences. What you shouldn't do is simply ignore the warnings or turn them off because you find them annoying.
Was This Post Helpful? 0
  • +
  • -

#4 Bryston  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 125
  • Joined: 24-January 12

Re: The evils of DevC++

Posted 09 February 2012 - 03:08 PM

oops, well don't i feel silly now... :)

i dit change my data to a double in the original program in DevC++ and it ran fine. This was my first time opening code::blocks, so I guess there is some setup to be done! Thanks for pointing that out. much appreciated.
Was This Post Helpful? 0
  • +
  • -

#5 Karel-Lodewijk  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 449
  • View blog
  • Posts: 849
  • Joined: 17-March 11

Re: The evils of DevC++

Posted 09 February 2012 - 04:02 PM

We had a similar argument a while back c++11 should not give you the ambiguous error message but will use the pow function using doubles, C++98 should flag it as ambiguous. The conversion to double is also safe, as long as the results fits inside the integer, the result will be exact.

Because:
a) The double version of pow will be used.
b) A double has more bits available for precision than an integer, so there will be no rounding errors.

But basically yes, there is more going on here than a crummy compiler, better make everything nice and explicit.

This post has been edited by Karel-Lodewijk: 09 February 2012 - 04:02 PM

Was This Post Helpful? 1
  • +
  • -

#6 Bryston  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 125
  • Joined: 24-January 12

Re: The evils of DevC++

Posted 09 February 2012 - 04:19 PM

View PostKarel-Lodewijk, on 09 February 2012 - 04:02 PM, said:

We had a similar argument a while back c++11 should not give you the ambiguous error message but will use the pow function using doubles, C++98 should flag it as ambiguous. The conversion to double is also safe, as long as the results fits inside the integer, the result will be exact.

Because:
a) The double version of pow will be used.
B) A double has more bits available for precision than an integer, so there will be no rounding errors.

But basically yes, there is more going on here than a crummy compiler, better make everything nice and explicit.


In this case an int is more than is needed.
        cout << "Converting " << number+1 << " to decimal." << endl;
        int decimal(0);
        for (int position(7); position >= 0; --position){
            if(binaries[number][position] != 0){
                int bit_value = pow(2, position);
                decimal += bit_value;
            }
        }


The max value that can be returned is 255. I have to keep reminding myself that bytes are cheap though. My only previous programming experience was in assembler with a 64k cap.
Was This Post Helpful? 0
  • +
  • -

#7 r.stiltskin  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 1833
  • View blog
  • Posts: 4,927
  • Joined: 27-December 05

Re: The evils of DevC++

Posted 09 February 2012 - 04:26 PM

I didn't mean to imply that there was anything wrong with the code -- just that the compiler should generate a warning. And then, knowing what it means and knowing that in this case it's not a problem, you're free to ignore it. You are, after all, smarter than the compiler.
Was This Post Helpful? 0
  • +
  • -

#8 Bryston  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 125
  • Joined: 24-January 12

Re: The evils of DevC++

Posted 09 February 2012 - 04:40 PM

Quote

You are, after all, smarter than the compiler.

I'm not so sure of that sometimes, I find myself arguing with it, telling it make more sense...
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1