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,762 of 33,346   
   ptyxs to All   
   Re: Are MACROS good and can the compiler   
   24 Dec 11 14:10:44   
   
   495da04d   
   From: kerloch@gmail.com   
      
   { Top-posting converted into bottom-posting.   
     Posters, please avoid top-posting. -mod }   
      
   Le 24/12/2011 01:44, Gene Bushuyev a écrit :   
   > On Dec 21, 1:14 pm, Mathias Gaunard  wrote:   
   >> On Dec 20, 8:55 am, DeMarcus  wrote:   
   >>   
   >>> Hi,   
   >>   
   >>> I don't like macros.   
   >>   
   >> Macros are an essential C and C++ feature that allows to generate   
   >> code.   
   >> You can do repetition, branching etc.   
   >>   
   >> Their main use is to avoid code repetition for things that cannot be   
   >> done by simply using functions (such as generating classes, a set of   
   >> functions, specializations, etc.)   
   >>   
   >> A lot of things can only be done with macros.   
   >   
   > I don't want to recite the list why macros is obnoxious, ugly, smelly,   
   > bad language feature. Herb Sutter already wrote that piece. I only   
   > want to mention a few things. If a macro cannot be reasonably   
   > eliminated from the code, it suggests to me that either the code   
   > design is wrong, or language is lacking a feature (reflection   
   > perhaps). I also found that automatic code generation can often be a   
   > better alternative to complicated macros. I definitely think trivial   
   > macros, which can be implemented using normal language features have   
   > no right to exist, and it makes sense to go an extra mile wiping them   
   > out. Who didn't curse MS every time they stumbled on their min/max   
   > macros.   
      
   For those who have the book by themselves, look at Effective C++ by   
   Scott Meyers Item 2 'Prefer consts, enums, and inlines to #define' for   
   some arguments against macros in C++. Note that Stroustrup in many   
   places (unfortunatley I have no precise reference at hand) claims macros   
   (which he humourously qualifies as 'nasty' or 'disgusting') should be   
   maximally avoided...   
      
      
   --   
         [ 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