//flex table opened by JP

Click to See Complete Forum and Search --> : Interesting


nothing
10-13-2003, 02:51 PM
First, take a look at this program:


#include <iostream>
using std::cout;
using std::endl;

int main()
{
cout << pow(2,2) << endl;

return 0;
}


I compiled and ran this program successfully under Linux, using gcc version 3.2.2. After a while, I noticed it is wrong, because I forgot to include the cmath reader file. So I started to wonder why did this program compiled if it is wrong. I decided to try to compile it using MS VC++ 6.0 and as I expected, it didn't compile because the cmath reader file was misssing. My question is: which one is right? GCC or MS VC++ 6.0?

neverwhere
10-13-2003, 02:53 PM
MS VC++

nothing
10-13-2003, 03:43 PM
Ok, WHY?

fishybawb
10-13-2003, 04:55 PM
But does it give the correct result? If you don't include the #include <math.h> directive, gcc (unlike VC++) defaults to the function declaration of pow(double x, double y). Possibly not what you intended :t

nothing
10-13-2003, 05:12 PM
The program returned 4. I think gcc is right because it is newer than VC++, which means it is supposed to be more standard compliant.

qball
10-13-2003, 11:55 PM
So I started to wonder why did this program compiled if it is wrong.


the program is not wrong.

why it compiles, ask compiler?

nothing
10-14-2003, 02:09 AM
:rolleyes:

finger51
10-20-2003, 07:37 PM
Originally posted by qball


the program is not wrong.

why it compiles, ask compiler?


ANOTHER HELPFUL POSTING BY QBALL!!!

nothing
10-20-2003, 10:05 PM
I was going to say the same thing but I decided to use a :rolleyes: instead.

fishybawb
10-21-2003, 03:41 PM
I'm not at all familiar with gcc these days, so this is just pure speculation - perhaps it "notices" the lack of the cmath header and just automatically uses it? It's a common library - who knows, maybe gcc's implementation of the pow() function is actually declared in the standard Linux iostream.h. That would seem a little "non-standard" though... :t