Can you force include a C++ header file in local files ONLY (Visual Studio 2022)?

Viewed 76

I'm experimenting with macros, such as replacing == with is, to make the syntax of C++ closer to C#. When I force include a header file containing these macros (i.e. #define is ==), it seems files even outside of my project are affected.

Example:
*bool __CLR_OR_THIS_CALL is(mask _Maskval, _Elem _Ch) const {*

in xlocale becomes
*bool __CLR_OR_THIS_CALL == (mask _Maskval, _Elem _Ch) const {*.

I only want these macros to be included in my source files, but I don't want to have to manually include the header file with the macro definitions in every file of my project. Can you configure the force include (/FI) feature of Visual Studio Community to be used only on source files?

1 Answers

#include "x.h" is a blunt instrument.

It literally replaces the include directive with the entire contents of x. In the case of Visual Studio's /FI feature it inserts the entire contents of x before the rest of the source file. Thus any macros that are defined in x included before y -- by whatever means, include order, via /FI, etc. -- will affect y.

Related