What is FORCEINLINE macro?

I made a Private component in the parent class and wanted to call it in the subclass. I used FORCEINLINE. What is the FORCEINLINE macro? Is there a better way to call Private builds?

UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "BaseAttribute", meta = (AllowPrivateAccess = "true"))
class UArrowComponent * OpenFirePoint;

public:
FORCEINLINE UArrowComponent * GetSpawnPoint() { return OpenFirePoint;}

5 Likes

It most likely macro that places __forceinline which is non-standard (not part of C++ specifications) keyword exclusive to VS compiler, that forces compiler to do inline unconditionally, because with standard inline compiler might not decide to do so, for it’s own optimization reasons (which might not understand what you trying to achieve)

Inline means that on call of that function compiler gonna paste function code to place of the call instead of doing standard jump to function call somewhere else juggling register values on the way, in theory it speeds up execution of function call, but in exchange you create multiple copies of function on every time you call it elsewhere in your C++ code making your machine code size bigger and it takes more memory as result. Compiler have a privilege to decide whatever it optimal to do so and have final decision to do so, force inline forces to do always inline.

To keep compatibility with other compilers (like clang for Linux and Mac), UE4 needs to have macro that gonna place other-compiler equivalent or just fallback to standard inline.

In general all keyword macros you see in UE4 (like MODULENAME_API is another example, that place extern keyword when your module is build to separate dll) are for UBT to control that keyword existence for specific build configurations and platform targets

16 Likes

hank you for your reply. I have a general idea.Is it a good way to get private components using FORCEINLINE macros?Is there a better way to get private components?`

class MYTOWERDEFENSE_API ARuleOfTheCharacter : 
{
	GENERATED_BODY()

	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "BaseAttribute", meta = (AllowPrivateAccess = "true"))
	class USceneComponent * HomingPoint;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "BaseAttribute", meta = (AllowPrivateAccess = "true"))
	class UWidgetComponent * ShowUMG;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "BaseAttribute", meta = (AllowPrivateAccess = "true"))
	class USceneComponent * ShowAttribute;
	UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "BaseAttribute", meta = (AllowPrivateAccess = "true"))
	class UArrowComponent * OpenFirePoint;
public:	
// 	FORCEINLINE UArrowComponent * GetSpawnPoint() { return OpenFirePoint;}
// 	FORCEINLINE USceneComponent * GetHomingPoint() { return HomingPoint;}