4

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;
}
Christian Rizov
  • 331
  • 2
  • 11

2 Answers2

6

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

M.M
  • 138,810
  • 21
  • 208
  • 365
3

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.

Theolodis
  • 4,977
  • 3
  • 34
  • 53
  • Thank you for the fast answer. – Christian Rizov Apr 26 '14 at 09:32
  • 1
    It is not about the compiler being strict. Standard library headers are allowed to include any number of other standard library headers. It is nothing to do with the compiler. It is to do with the standard library implementations. – juanchopanza Apr 26 '14 at 11:39