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,753 of 33,346   
   Ulrich Eckhardt to All   
   Re: Are MACROS good and can the compiler   
   20 Dec 11 12:06:02   
   
   From: ulrich.eckhardt@dominolaser.com   
      
   Am 20.12.2011 08:55, schrieb DeMarcus:   
   > 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.   
   >   
   > My question is; if NDEBUG is set, is it common behavior that the   
   > compiler will see that debugPrint() is empty and then remove the   
   > function call completely so I get the same removal behavior as a macro?   
      
   I'd expect the compiler to always remove/inline the function call, since   
   the function itself only calls two other functions. In the case of an   
   empty body it is very likely that it really is removed, in particular   
   when it is declared as "inline", because that is a trivial optimization.   
   The only case where that would not be the case is when explicitly told   
   not to, i.e. when compiling for debugging.   
      
      
   Uli   
      
      
   --   
         [ 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