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 31,754 of 33,346   
   Vladimir Jovic to DeMarcus   
   Re: Are MACROS good and can the compiler   
   20 Dec 11 12:08:26   
   
   From: vladaspams@gmail.com   
      
   On 20/12/11 08:55, DeMarcus wrote:   
   > Hi,   
   >   
   > I don't like macros.   
   > The worst thing I know is macros spread all over the code like:   
   >   
   > DEBUG_PRINT("Some text");   
   >   
   > I still see one benefit with macros; you can remove code completely.   
   >   
   > Therefore I was thinking of the following solution:   
   >   
   > inline void debugPrint( const std::string& text )   
   > {   
   > #ifndef NDEBUG   
   >   std::cout << text << std::endl;   
   > #endif   
   > }   
   >   
   > This way I remove the macros from all over the code. I still have some   
   > ugly preprocessor code though (#ifndef) but it's now centralized to one   
   > place.   
   >   
      
   A better way to print a log messages would be using a version of   
   DEBUG_PRINT macro that print the line number, which would be implemented as:   
   inline void debugPrint( const std::string& text, const int atLine )   
   {   
   #ifndef NDEBUG   
     std::cout << text << "Happened at line number" << atLine << std::endl;   
   #endif   
   }   
      
   Now, it would be even better to print the file where it happened :   
   inline void debugPrint( const std::string& text, const int atLine, const   
   std::string file )   
   {   
   #ifndef NDEBUG   
     std::cout << text << "Happened at line number" << atLine << " in the   
   file " << file << std::endl;   
   #endif   
   }   
      
   This can be done using next macro:   
   #define DEBUG_PRINT(x) std::cout << text << "Happened at line number" <<   
   __LINE__ << " in the file " << __FILE__ << std::endl;   
      
      
   --   
         [ 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