C++ and heavy use of macros


I see in Unreal Engine 4 source code a heavy use of macros. Some of them are defined in source code, some of them are not. I’d like to study all of them and learn what they do and when are they necessary. Where can I find the definitions of macros that are not defined in source code?


Can you give an example of a macro that you aren’t finding. All of the unreal specific macros should be in the source code, though finding them can sometimes be harder because Visual Assist does a poor job of taking you to them and searching results in a large amount of data. Some are also defined in .inl files, not .cpp so the default search file types will ignore those files.

Ocean may also be referring to the Project, and not the full engine source code from github, which exposes much more of the inner workings of the engine.

Some macros are used for DLL linkage. Those are the various macros that end with the “_API” suffix. These are passed directly to the compiler by UnrealBuildTool. There are only a few other macros like this that are not defined in the code, and most of them are standard platform boilerplate macros (_MSC_VER, WINVER, etc.)

UObject classes do use macros such as UPROPERTY and UFUNCtION, but they actually just empty stubs for UnrealHeaderTool to parse. They are more like ‘attributes’ than macros.


Yes, I’ve noticed that Xcode cannot find the definition for some macros ending with “_API” suffix like for example ENGINE_API or CORE_API. I presume that I can still see how ENGINE_API is defined because the project is building successfully so the UnrealBuildTool is providing definitions for this. Could you tell me where can I find this information?

For the various *API macros, those are defined in UEBuildModule.cs (see the SetupPublicCompileEnvironment() function.) Those macros are a very special case, because they are synthesized automatically based on which other modules any given module is importing. Those imports are controlled with the module’s *Build.cs script. For example, in order for ENGINE_API to be defined while compiling my module’s code, I would need to specify “Engine” as a dependency module in my *Build.cs script.


Many thanks Mike, I will look into that.