x

Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

Weird bug in C++: Macros definition for logging

I have created several macroses for easy logging.

The first 2 work fine. The third brings up a compile error, saying that there should be one more parentheses ')' before ';" when calling the macro.

DEFINITION:

 #define LOG_WTF(param1) UE_LOG(LogTemp, Warning, TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString(param1))
 #define LOG_WTS(param1) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString(param1)))
 #define LOG_WTS2(_formatString, ...) GEngine->AddOnScreenDebugMessage(-1, 15.0f, FColor::Yellow, FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(_formatString), ##__VA_ARGS__) )
 

USAGE:

 LOG_WTF("This is a warning testLog to file");
 LOG_WTS("This is a warning testLog to screen");
 LOG_WTS2("This is a warning testLog to screen: LOG_WTS2"));
 LOG_WTS2("This is a warning testLog to screen: %s = %d", TEXT("bla"), 123));

Note: The last two lines are used to call the "LOG_WTS2" macro without and with extra parameters. If I write the code properly, the compiler tells me to put another ')' before ';' at the end of these two lines. When I put the extra ')' for each line, the code is compiled and the log is projected correctly to the screen. It seems like an issue within the definition of macros "LOG_WTS2". What is wrong with the code and how can it be fixed?

Update:

After redefining "LOG_WTF" with the same input as "LOG_WTS", there were no problems with compilation when using the correct syntax, without the extra parentheses ')'.

 DEFINITION:
 
 #define LOG_WTF(FormatedString, ...) UE_LOG(LogTemp, Warning, TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(FormatedString), ##__VA_ARGS__) )
 
 USAGE:
 
 LOG_WTF("This is a warning testLog to file");
 LOG_WTF("This is a warning testLog to file: %s = %d", TEXT("bla"), 123);
 LOG_WTS("This is a warning testLog to screen: %s = %d", TEXT("bla"), 123));


Update 2:

When calling "LOG_WTS" from another macro, the compiler still demands using an extra parentheses at the end of macro call:

DEFINITION:

 #define LOG_WTA(FormattedString, ...) LOG_WTF(FormattedString, ##__VA_ARGS__) LOG_WTS(FormattedString, ##__VA_ARGS__)

USAGE:

 LOG_WTA("This is a warning testLog to WTA: %s = %d", TEXT("bla"), 123));

Product Version: UE 4.19
Tags:
more ▼

asked Dec 04 '18 at 01:48 PM in C++ Programming

avatar image

Constantin Suman
39 2 7

(comments are locked)
10|2000 characters needed characters left

1 answer: sort voted first

If you look at the WTS macro, the one that calls AddOnScreenDebugMessage, at the end the first closing ) closes the inner Printf

 *FString::Printf(TEXT(_formatString), ##__VA_ARGS__

the second ) closes the outer Printf

 FString::Printf(TEXT("ArcWare Log: %s (line:%d) Warning: %s"), *FString(__FUNCTION__), __LINE__, *FString::Printf(TEXT(_formatString), ##__VA_ARGS__)

which means you never closed the actual function call to AddOnScreenDebugMessage. You need a third ) at the end of that macro to match.

more ▼

answered Dec 06 '18 at 05:10 PM

avatar image

Brian Johnstone STAFF
311 4 3 2

(comments are locked)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question