Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8309365
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T19:05:42+00:00 2026-06-08T19:05:42+00:00

Apparently the preprocessor macros in C++ are justifiably feared and shunned by the C++

  • 0

Apparently the preprocessor macros in C++ are

justifiably feared and shunned by the C++ community.

However, there are several cases where C++ macros are beneficial.

Seeing as preprocessor macros can be extremely useful and can reduce repetitive code in a very straightforward manner —

— leaves me with the question, what exactly is it that makes preprocessor macros “evil”, or, as the question title says, which feature (or removal of feature) would be needed from preprocessor macros to make them useful as a “good” development tool (instead of a fill-in that everyone’s ashamed of when using it). (After all, the Lisp languages seem to embrace macros.)

Please Note: This is not about #include or #pragma or #ifdef. This is about #define MY_MACRO(...) ...

Note: I do not intend for this question to be subjective. Should you think it is, feel free to vote to move it to programmers.SE.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T19:05:44+00:00Added an answer on June 8, 2026 at 7:05 pm

    Most preprocessor abuse come from misunderstanding, to quote Paul Mensonides(the author of the Boost.Preprocessor library):

    Virtually all
    issues related to the misuse of the preprocessor stems from attempting to
    make object-like macros look like constant variables and function-like
    macro invocations look like underlying-language function calls. At best,
    the correlation between function-like macro invocations and function calls
    should be incidental. It should never be considered to be a goal. That
    is a fundamentally broken mentality.

    As the preprocessor is well integrated into C++, its easier to blur the line, and most people don’t see a difference. For example, ask someone to write a macro to add two numbers together, most people will write something like this:

    #define ADD(x, y) ((x) + (y))
    

    This is completely wrong. Runs this through the preprocessor:

    #define ADD(x, y) ((x) + (y))
    ADD(1, 2) // outputs ((1) + (2))
    

    But the answer should be 3, since adding 1 to 2 is 3. Yet instead a macro is written to generate a C++ expression. Not only that, it could be thought of as a C++ function, but its not. This is where it leads to abuse. Its just generating a C++ expression, and a function is a much better way to go.

    Furthermore, macros don’t work like functions at all. The preprocessor works through a process of scanning and expanding macros, which is very different than using a call stack to call functions.

    There are times it can be acceptable for macros to generate C++ code, as long as it isn’t blurring the lines. Just like if you were to use python as a preprocessor to generate code, the preprocessor can do the same, and has the advantage that it doesn’t need an extra build step.

    Also, the preprocessor can be used with DSLs, like here and here, but these DSLs have a predefined grammar in the preprocessor, that it uses to generate C++ code. Its not really blurring the lines since it uses a different grammar.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Apparently #filter_chain is deprecated, does anyone know how? I've tried several things, but can't
Apparently MapReduce queries are one of the slowest things one can do in MongoDB
Apparently there's a maximum number of arguments for std::thread for the std::thread implementation in
Apparently, there's been a big brouhaha over whether or not Python needs tail-call optimization
Apparently there is a database postgres that is created by default on each postgresql
Apparently, you can't call apply with a record constructor: (defrecord Foo. [id field]) (apply
Apparently the font Arvo is supposed to work fine in IE, but I can't
Apparently there is no predefined list available in .net. I'd like to use a
Apparently in VS2008 SP1 there's an option under Publish | Options to have a
Apparently, in Flash 10, you can use the GPU to calculate shaders, and if

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.