From The Compiler, 6 Years ago, written in C.
Embed
  1. /*
  2.  * Variant 1
  3.  */
  4.  
  5. // in globals.h:
  6. #define HSCmdError(...) \
  7.         do { \
  8.                 g_string_append_printf(output, "%s: error: ", argv[0]); \
  9.                 g_string_append_printf(output, __VA_ARGS__); \
  10.         } while(0)
  11.        
  12. // In use():
  13. HSCmdError("Can't find tag \"%s\"", argv[1]);
  14.  
  15. // In raise():
  16. HSCmdError("Can't find window \"%s\"", argv[1]);
  17.  
  18. // +: cleaner code
  19. // -: macro modifying local variables
  20.  
  21. /*
  22.  * Variant 2
  23.  */
  24.  
  25. // In use():
  26. g_string_append_printf(output,
  27.         "%s: error: Can't find tag \"%s\"", argv[0], argv[1]);
  28.  
  29. // In raise():
  30. g_string_append_printf(output,
  31.         "%s: error: Can't find window \"%s\"", argv[0], argv[1]);
  32.  
  33. // +: no weird macro
  34. // -: unclean code, much repetition