Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ math functions can be used without including the directive "math.h" in VS 2013

I am very curious why I can use the math functions in C++ without including the "math.h". I can't find an answer with google search.

Here is the simple code I am executing. Everything is compiling and running.

#include <iostream>

using namespace std;

int main()
{
    const float PI = acosf(-1);
    cout << PI << endl;

    return 0;
}
like image 741
Christian Rizov Avatar asked Jan 11 '23 17:01

Christian Rizov


2 Answers

Any standard header is allowed to include any other standard header.

like image 141
M.M Avatar answered Jan 24 '23 08:01

M.M


if you would compile the same with gcc-4.8 it would complain.

Keep in mind that this is not something to rely on if you want your code to be portable and compilable on different versions of the same or different compilers.

like image 43
Theolodis Avatar answered Jan 24 '23 09:01

Theolodis