Mac log function names?

In xcode the following causes a failed build error: use of undeclared identifier ‘L__func__’



#if _MSC_VER
#define FUNC_NAME    TEXT(__FUNCTION__)
#else // FIXME - GCC?
#define FUNC_NAME    TEXT(__func__) # this causes error on mac
#endif


Note this code is from A new, community-hosted Unreal Engine Wiki - Announcements and Releases - Unreal Engine Forums

I have tried FUNCTION and __PRETTY_FUNCTION. Both same issues. If I remove the TEXT macro then it compiles but viewing the output log in the editor causes the editor to crash if I log the value of FUNC_NAME.

Anyone know how to log function names on a mac?

I fixed this by doing this



#define FUNC_NAME    *FString(__func__)


I have no idea if that is bad or not but seems to be working

1 Like

Did you see what TEXT() expands to? As you can see it’s just L so that doing TEXT(“Hello”) expands to L"Hello". I would imagine you want to use FName(func), however I think you want FUNCTION rather than func.

FName(FUNCTION) causes the game to crash when its logged in some low level string class.

*FString(FUNCTION) does work though so i changed to that…not sure if func is different than function but all seems to be working the same.

What about just FUNCTION?

With only FUNCTION that crashes the editor when viewing the output log.

Its working though with how i have it with *FString so im not going to mess with it anymore.

Well using FString operator * returns const TCHAR *, so there is no point in using it as it must be the same as TEXT(“Hello”). So this should work:

UE_LOG(LogTemp, Log, TEXT("I am in function %s"), TEXT(__FUNCTION__));

I added your UE_LOG(LogTemp, Log, TEXT(“I am in function %s”), TEXT(FUNCTION)); to the player controller begin play function and it wont compile. Same error as in OP.

error: use of undeclared identifier ‘L__FUNCTION__’

Hehe, of course, this is where I came in :slight_smile: Sorry. You want something like this.

#define WIDE2(x) L##x
#define WIDECHAR(x) WIDE2(x)

#define WIDE_FUNCTION WIDECHAR(FUNCTION)

I wasn’t able to get any of the above suggestions to work, but found this pattern works

#define CUR_CLASS_FUNC (FString(__FUNCTION__))
UE_LOG(LogTemp, Log, TEXT("I am in function %s:"), *CUR_CLASS_FUNC);
2 Likes