Sign in to follow this  
Feidias

VC automatic headers

Recommended Posts

When you use some common functions like fread there is no need to include the header (stdio.h in this case) which is bad when you try to write compatible source code. Is there any way to turn off these "automatic headers" in VC?

Share this post


Link to post
Share on other sites
Does your project use precompiled headers?

The Visual C++ IDE may set up an stdafx.h header for precompilation on your behalf, depending on the settings you selected when creating the project. Check the contents of this header. You may want to remove it entirely if you're really against PCH. Other precompiled headers may be in your project if it's an existing code base.

Most compilers (MSVC included) support "forced includes", where you can tell the compiler to always #include a header at the beginning of the preprocessing stage. It's possible that cstdio or stdio.h is being force-included. This will likely be buried in the project options somewhere. Look for the /FI switch.

If none of this is ringing true, can you provide a little more information?

Share this post


Link to post
Share on other sites
Quote:
Original post by Feidias
When you use some common functions like fread there is no need to include the header (stdio.h in this case) which is bad when you try to write compatible source code. Is there any way to turn off these "automatic headers" in VC?


No standard usage of VS should cause it to include a header file in a TU without you explicitly using the #include directive to bring that header in, or to bring in a header that itself directly or indirectly includes that header.

Share this post


Link to post
Share on other sites
MSVC does automatically includes a number of symbols that don't require any headers. For example, this will compile under MSVC 2008:

int main(int, char **) {
size_t s = sizeof(__s_GUID);
}

without any includes despite the fact that size_t is supposed to be defined in cstddef and __s_GUID being another symbol that has no declaration. AFAIK, there's no way to disable this behavior.

Share this post


Link to post
Share on other sites
There is also the /FI compiler option (accessible from C/C++ -> Advanced project options), which forces MSVC to include the specified headers at the top of every source file. We have a file called "Always.h" at work that should, well, always be included first and we use this option to ensure that it is.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this