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,892 of 33,346   
   Andre Kaufmann to Dave Abrahams   
   Re: Are MACROS good and can the compiler   
   07 Feb 12 01:46:28   
   
   From: akfmnews@t-online.de   
      
   "Dave Abrahams"  wrote in news:m2wr9m93o8.fsf@pluto.luannocracy.com...   
      
   >[...]   
      
   >Macros, like any useful language feature, are neither good nor bad.   
      
   Perhaps macros would be part of the language and not of the preprocessor   
   they   
   wouldn't be that evil. At least I think there are more downsides regarding   
   macros than   
   advantages.   
      
   >> I also found that automatic code generation can often be a better   
   >> alternative to complicated macros.   
   >[...] My experience writing Boost.Python led me to the opposite conclusion.   
   >I   
      
   >1. Before the change, my users couldn't figure out how to run the   
         [...]   
      
   You solved this problem by using macros, but perhaps there might have been   
   another   
   solution to make it easier for users to tweak and execute the code   
   generator.   
   But generally I agree - for a library writer it's perhaps easier to ship   
   macros / templates than   
   code generators.   
      
   >2. The scripts were actually harder to maintain than the   
   Yes, that's true. But I think it depends on how the code is generated. If   
   it's mainly   
   data (enumerations, constants etc. small helper functions) and not code it's   
   easier to maintain   
   such code with code generation than macros or templates (IMHO).   
      
   >[...]   
      
   Nobody should put macros in the "global namespace" in header files.   
      
   Agreed - but sometimes "generated" code must be used in header files too,   
   which would imply   
   to use macros in header files too if macros are used instead of code   
   generation.   
      
   >[...]   
      
      
   The main problem I have with macros is:   
      
   a) I can't see (easily) the expanded code   
   b) I can't debug the generated code, besides on assembly level   
   c) Code bloat - I have the impression that compilers can't optimize   
      code which is using macros and templates that good.   
      
   If the macros/templates are just simple single line macros (e.g. like   
   ASSERT)   
   I don't have a problem with them (besides that they prevent the compiler   
   from being able to precompile cpp units).   
      
      
   Andre K   
      
      
   --   
         [ 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