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,912 of 33,346    |
|    Martin B. to Andre Kaufmann    |
|    Re: Are MACROS good and can the compiler    |
|    12 Feb 12 23:25:12    |
      From: 0xCDCDCDCD@gmx.at              On 12.02.2012 20:29, Andre Kaufmann wrote:       >>> Or, optionally, they should be more flexible, so that they could replace       >>> code generators.       >       > "Mathias Gaunard" wrote       >       >> They usually can, most people just don't know how to use them.       >       > (...)       >       > Yes, so far you are correct, alternatively macros can be used in many       > cases, where code generators are used.       > But that wasn't my point:       >       > - Macros prevent the compiler to be as fast in compilation as compilers       > of other languages. Because each       > header file as to be compiled again and again and again. C++ compilers       > generate highly efficient code,       > but in contrast the compiler itself can't be that efficient regarding       > compilation speed       >              That's the preprocessor in general, not macros specifically, or isn't it?              > - Macros pollute the global namespace. (...)       > - Macros don't support namespaces.       >              IMHO, the namespace problem with macros is *far* too much exaggerated.       Sure, MS/Windows defining macros named `min()` and `max()` was (is) dead       stupid, but `BOOST_FOREACH()` or `MY_THROW_CONTEXT_AWARE_EXCEPTION()` is       hardly going to collide with anything.              > - Macros are hard to debug. If macros expand to a huge piece of code,       > you can't simply step into the code       > or see which line of code caused a crash when analyzing a crash dump       >              As far as I'm concerned, that is clearly a fault of the tools. Macros       have been here for ages, the fact that debuggers still don't do a proper       job of helping the developer with macros is just plain awful.              > - Macros have the same problem as templates: You can't see the generated       > code (WYSWIG) easily and       > IDE code completion is limited, compared to "normal code"       >              Actually, with macros it's *better*. I guess any decent compiler/prep       allows you to view the preprocessed code, wich isn't something that can       be said for templates. (But then again, templates don't do as much       substitution magic as macros can do.)              > - An invalid macro in a header file can cause hours of happy debugging,       > (...)       > Just in contrast to code generators, where you can debug and see the       > expanded code.       > Macros have the advantage to be built into the "language"       > (preprocessor). But IMHO this doesn't outweigh       > the disadvantages.       >              A code generator is making the implicit maccro step explicit via an       additional tool. This can indeed be either an advantage or a       disadvantage. :-)              cheers,       Martin              --       Good C++ code is better than good C code, but       bad C++ can be much, much worse than bad C code.                      [ 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