Using the * in the UE_LOG

So I understand why there is a * when creating a pointer or when dereferencing one, but why do we need it in the UE_LOG? In the example, FString Name is not a pointer, but in the UE_LOG he writes *Name. Why?

It’s an overloaded operator
image

I’m afraid I don’t understand. Could you elaborate please?

FString Thing;
*Thing;

Will call that function in that screenshot which returns the pointer to the first element in the character array that it is storing if it’s not empty, otherwise it will return an empty string literal. This is because FString has overloaded that operator.
See https://godbolt.org/z/c9Efea5G6 on an example of operator overloading.

If you meant elaborating on why it’s needed. Then that is because UE_LOG and some other bits of Unreal are using C API’s. The way C does strings is by having them end in a null character and pass them around as pointers. Then any C function expecting a string will just keep reading bytes until it sees the null character.

Example you could loop a character array like:

const char string[6] = "Hello"; // implicitly ends in '\0'
                                // hence the array size is 6 not 5.
// implicit converssion from array to pointer in `ptr = string`
for (const char* ptr = string; *ptr != '\0'; ++ptr)
{
    // read the characters
}

So we use the * in UE_LOG for all strings? Okay, that’s what I needed to know. Thank you!

Specifically FStrings. Because internally it is using one of the printf functions.
You wouldn’t need it for a literal for example.

UE_LOG(LogTemp, Warning, TEXT("Hello %s"), TEXT("Tyler"))
1 Like

Perfect, thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms