@@ -225,31 +225,31 @@ enum LogTriState
225225// USE LOG() INSTEAD
226226//
227227#ifndef _MSC_VER
228- #define LOG_IMPL (str, ...) \
229- { \
228+ #define LOG_IMPL (str, ...) \
229+ do { \
230230 if (LOG_TARGET != nullptr ) \
231231 { \
232232 fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL, __VA_ARGS__); \
233233 fflush (LOG_TARGET); \
234234 } \
235- }
235+ } while ( 0 )
236236#else
237- #define LOG_IMPL (str, ...) \
238- { \
237+ #define LOG_IMPL (str, ...) \
238+ do { \
239239 if (LOG_TARGET != nullptr ) \
240240 { \
241241 fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL " " , ##__VA_ARGS__); \
242242 fflush (LOG_TARGET); \
243243 } \
244- }
244+ } while ( 0 )
245245#endif
246246
247247// INTERNAL, DO NOT USE
248248// USE LOG_TEE() INSTEAD
249249//
250250#ifndef _MSC_VER
251- #define LOG_TEE_IMPL (str, ...) \
252- { \
251+ #define LOG_TEE_IMPL (str, ...) \
252+ do { \
253253 if (LOG_TARGET != nullptr ) \
254254 { \
255255 fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL, __VA_ARGS__); \
@@ -260,10 +260,10 @@ enum LogTriState
260260 fprintf (LOG_TEE_TARGET, LOG_TEE_TIMESTAMP_FMT LOG_TEE_FLF_FMT str " %s" LOG_TEE_TIMESTAMP_VAL LOG_TEE_FLF_VAL, __VA_ARGS__); \
261261 fflush (LOG_TEE_TARGET); \
262262 } \
263- }
263+ } while ( 0 )
264264#else
265- #define LOG_TEE_IMPL (str, ...) \
266- { \
265+ #define LOG_TEE_IMPL (str, ...) \
266+ do { \
267267 if (LOG_TARGET != nullptr ) \
268268 { \
269269 fprintf (LOG_TARGET, LOG_TIMESTAMP_FMT LOG_FLF_FMT str " %s" LOG_TIMESTAMP_VAL LOG_FLF_VAL " " , ##__VA_ARGS__); \
@@ -274,7 +274,7 @@ enum LogTriState
274274 fprintf (LOG_TEE_TARGET, LOG_TEE_TIMESTAMP_FMT LOG_TEE_FLF_FMT str " %s" LOG_TEE_TIMESTAMP_VAL LOG_TEE_FLF_VAL " " , ##__VA_ARGS__); \
275275 fflush (LOG_TEE_TARGET); \
276276 } \
277- }
277+ } while ( 0 )
278278#endif
279279
280280// The '\0' as a last argument, is a trick to bypass the silly
@@ -435,41 +435,41 @@ inline FILE *log_handler() { return log_handler1_impl(); }
435435inline void log_test ()
436436{
437437 log_disable ();
438- LOG (" 01 Hello World to nobody, because logs are disabled!\n " )
438+ LOG (" 01 Hello World to nobody, because logs are disabled!\n " );
439439 log_enable ();
440- LOG (" 02 Hello World to default output, which is \" %s\" ( Yaaay, arguments! )!\n " , LOG_STRINGIZE (LOG_TARGET))
441- LOG_TEE (" 03 Hello World to **both** default output and " LOG_TEE_TARGET_STRING " !\n " )
440+ LOG (" 02 Hello World to default output, which is \" %s\" ( Yaaay, arguments! )!\n " , LOG_STRINGIZE (LOG_TARGET));
441+ LOG_TEE (" 03 Hello World to **both** default output and " LOG_TEE_TARGET_STRING " !\n " );
442442 log_set_target (stderr);
443- LOG (" 04 Hello World to stderr!\n " )
444- LOG_TEE (" 05 Hello World TEE with double printing to stderr prevented!\n " )
443+ LOG (" 04 Hello World to stderr!\n " );
444+ LOG_TEE (" 05 Hello World TEE with double printing to stderr prevented!\n " );
445445 log_set_target (LOG_DEFAULT_FILE_NAME);
446- LOG (" 06 Hello World to default log file!\n " )
446+ LOG (" 06 Hello World to default log file!\n " );
447447 log_set_target (stdout);
448- LOG (" 07 Hello World to stdout!\n " )
448+ LOG (" 07 Hello World to stdout!\n " );
449449 log_set_target (LOG_DEFAULT_FILE_NAME);
450- LOG (" 08 Hello World to default log file again!\n " )
450+ LOG (" 08 Hello World to default log file again!\n " );
451451 log_disable ();
452- LOG (" 09 Hello World _1_ into the void!\n " )
452+ LOG (" 09 Hello World _1_ into the void!\n " );
453453 log_enable ();
454- LOG (" 10 Hello World back from the void ( you should not see _1_ in the log or the output )!\n " )
454+ LOG (" 10 Hello World back from the void ( you should not see _1_ in the log or the output )!\n " );
455455 log_disable ();
456456 log_set_target (" llama.anotherlog.log" );
457- LOG (" 11 Hello World _2_ to nobody, new target was selected but logs are still disabled!\n " )
457+ LOG (" 11 Hello World _2_ to nobody, new target was selected but logs are still disabled!\n " );
458458 log_enable ();
459- LOG (" 12 Hello World this time in a new file ( you should not see _2_ in the log or the output )?\n " )
459+ LOG (" 12 Hello World this time in a new file ( you should not see _2_ in the log or the output )?\n " );
460460 log_set_target (" llama.yetanotherlog.log" );
461- LOG (" 13 Hello World this time in yet new file?\n " )
461+ LOG (" 13 Hello World this time in yet new file?\n " );
462462 log_set_target (log_filename_generator (" llama_autonamed" , " log" ));
463- LOG (" 14 Hello World in log with generated filename!\n " )
463+ LOG (" 14 Hello World in log with generated filename!\n " );
464464#ifdef _MSC_VER
465- LOG_TEE (" 15 Hello msvc TEE without arguments\n " )
466- LOG_TEE (" 16 Hello msvc TEE with (%d)(%s) arguments\n " , 1 , " test" )
467- LOG_TEELN (" 17 Hello msvc TEELN without arguments\n " )
468- LOG_TEELN (" 18 Hello msvc TEELN with (%d)(%s) arguments\n " , 1 , " test" )
469- LOG (" 19 Hello msvc LOG without arguments\n " )
470- LOG (" 20 Hello msvc LOG with (%d)(%s) arguments\n " , 1 , " test" )
471- LOGLN (" 21 Hello msvc LOGLN without arguments\n " )
472- LOGLN (" 22 Hello msvc LOGLN with (%d)(%s) arguments\n " , 1 , " test" )
465+ LOG_TEE (" 15 Hello msvc TEE without arguments\n " );
466+ LOG_TEE (" 16 Hello msvc TEE with (%d)(%s) arguments\n " , 1 , " test" );
467+ LOG_TEELN (" 17 Hello msvc TEELN without arguments\n " );
468+ LOG_TEELN (" 18 Hello msvc TEELN with (%d)(%s) arguments\n " , 1 , " test" );
469+ LOG (" 19 Hello msvc LOG without arguments\n " );
470+ LOG (" 20 Hello msvc LOG with (%d)(%s) arguments\n " , 1 , " test" );
471+ LOGLN (" 21 Hello msvc LOGLN without arguments\n " );
472+ LOGLN (" 22 Hello msvc LOGLN with (%d)(%s) arguments\n " , 1 , " test" );
473473#endif
474474}
475475
@@ -542,7 +542,7 @@ inline void log_dump_cmdline_impl(int argc, char **argv)
542542 buf << " " << argv[i];
543543 }
544544 }
545- LOGLN (" Cmd:%s" , buf.str ().c_str ())
545+ LOGLN (" Cmd:%s" , buf.str ().c_str ());
546546}
547547
548548#define log_tostr (var ) log_var_to_string_impl(var).c_str()
@@ -620,10 +620,10 @@ inline std::string log_var_to_string_impl(const std::vector<int> & var)
620620#define LOGLN (...) // dummy stub
621621
622622#undef LOG_TEE
623- #define LOG_TEE (...) fprintf(stderr, __VA_ARGS__); // convert to normal fprintf
623+ #define LOG_TEE (...) fprintf(stderr, __VA_ARGS__) // convert to normal fprintf
624624
625625#undef LOG_TEELN
626- #define LOG_TEELN (...) fprintf(stderr, __VA_ARGS__); // convert to normal fprintf
626+ #define LOG_TEELN (...) fprintf(stderr, __VA_ARGS__) // convert to normal fprintf
627627
628628#undef LOG_DISABLE
629629#define LOG_DISABLE () // dummy stub
0 commit comments