home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,754 of 33,346   
   fmatthew5876 to DeMarcus   
   Re: Wouldn't it be good to refactor __LI   
   17 Dec 12 16:32:49   
   
   From: fmatthew5876@googlemail.com   
      
   On Sunday, December 16, 2012 10:48:31 PM UTC-5, DeMarcus wrote:   
      
   > What do you think about my idea?   
      
   I'd really really like to see some way of using __LINE__, __FILE__, and   
   __func__ without the preprocessor. I don't care whether or not they themselves   
   are macros, its just that you have to use a macro if you want to print   
   them automatically.   
      
   One thing I often like to do is create log functions that automatically prepend   
   headers to log message with this info.   
      
   Currently, the only way to do this is to use a macro like:   
   #define LOGERR(fmt, ...) fprintf(stderr, __FILE__ ":%d Error: " fmt, __LINE__,   
   #__VA_ARGS__)   
      
   I don't care that macros are considered evil or dangerous, the problem   
   with this is that you cannot put it into a namespace. Symbols in the default   
   namespace are never a good thing for library development.   
      
   Another possibility would be some way to make them refer to the callee instead   
   of the caller for inline functions. Then you can do:   
      
   namespace foo {   
   template  inline void logerr(const char* fmt, Args... args) {   
   fprintf(stderr, __CALLER_FILE__ ":%d Error:" fmt, __CALLER_LINE__, args...);   
   }   
      
   Of course this would require logerr to be an inline function for the compiler   
   to know the callers line and file information.   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca