Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual C++ 'Force Includes' option

Tags:

c++

visual-c++

I have just come across a Visual C++ option that allows you to force file(s) to be included - this came about when I was looking at some code that was missing a #include "StdAfx.h" on each .cpp file, but was actually doing so via this option.

The option can be found on the Advanced C/C++ Configuration Properties page and equates to the /FI compiler option.

This option could prove really useful but before I rush off and start using it I thought I'd ask if there are any gotchas?

like image 453
Rob Avatar asked Nov 26 '08 13:11

Rob


2 Answers

I would say the opposite to litb above if you're using precompiled headers. If you use "stdafx.h" as your precompiled header and have code like this:

#include "afile.h"
#include "stdafx.h"

then you'll be spending an age trying to figure out why "afile.h" isn't being included. When using precompiled headers, all the includes and #defines are ignored up to the "stdafx.h". So, if you force include the "stdafx.h" then the above will never happen and you'll get a project that uses the precompiled option efficiently.

As for litb's comment about finding macros, good IDE's usually have an option to jump to the definition of a symbol, whether it be a #define, function, class, etc.

like image 164
Skizz Avatar answered Oct 03 '22 04:10

Skizz


I would discourage from /FI (MSDN says it's called /FI . Not sure whether i looked at the right page though), simply because people or yourself reading the files don't notice a header is magically included anyway.

You can be sure this will cause much debugging time for someone that wants to figure out where specific macros come from, even though there are no #include lines at the top of the file.

like image 20
Johannes Schaub - litb Avatar answered Oct 03 '22 05:10

Johannes Schaub - litb