Reputation: 2744
I just wrote a simple C++ program in Visual Studio 2010 and I use ceil
function. But I forgot to include the <cmath>
and only included the <iostream>
. Surprisingly my code compiled successfully and ran without any error. I read a C++ book and it clearly says that to use ceil
function you must include <cmath>
or <math.h>
. Why this happens? Can anyone explain me? Thanks!
Upvotes: 2
Views: 729
Reputation: 393583
The header is indirectly included from some other (indirectly) included header.
To find out which one, enable 'keep preprocessed source' (/P
) from the project options and inspect the resulting (*.i) file
Update Just found out that VS2010 has renamed the related option:
Upvotes: 1
Reputation: 471409
Technically speaking, implementations are allowed to automatically include any header in the system headers. But this is implementation defined.
In some cases, <cmath>
is already included, in other cases, it isn't - same applies to all the other standard headers.
This issue came up on this question: https://stackoverflow.com/questions/7632926/is-this-a-c-program-or-c-program-how-to-decide
That aside, it's possible that it could be indirectly included by other includes.
Upvotes: 1