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 8457119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T12:43:38+00:00 2026-06-10T12:43:38+00:00

I am reading the book C++ Coding Standards: 101 Rules, Guidelines, and Best Practices,

  • 0

I am reading the book C++ Coding Standards: 101 Rules, Guidelines, and Best Practices, and it says that using #define is bad to use. When I was looking at some of the header files they have many #defines. If it’s bad to use #defines, why is there so many? Thank you.

  • 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-10T12:43:40+00:00Added an answer on June 10, 2026 at 12:43 pm

    #define are a bad practice because:

    They don’t have any Scope:

    #defines don’t respect scopes so there is no way to create a class scoped namespace. While variables can be scoped in classes.

    Weird magical numbers during compilation errors:

    If you are using #define those are replaced by the pre-processor at time of precompilation So if you receive an error during compilation, it will be confusing because the error message wont refer the macro name but the value and it will appear a sudden value, and one would waste lot of time tracking it down in code.

    Debugging Problems:

    Also for same reasons mentioned in #2, while debugging #define won’t provide much of an help really.

    Hence it is much better idea to use const variables instead of a #define.
    They are superior to #define in all above mentioned aspects.Only areas where #define can be really helpful are where you need actual textual replacement in code or in defining include header guards.

    Why are #definewidely used in C standard header files?

    One reason that comes to my mind is, In C(unlike C++) const declarations do not produce constant expressions.Which means prior to introduction of Variable length arrays in C standard one cannot write something like:

    const int max_val = 100;  
    int foos[max_val]; 
    

    because in C max_val is not a compile time constant, and prior to introduction of VLA’s array subscripts were needed to be compile time constants.
    So one had to write this instead as:

    #define MAX_VAL 100  
    int foos[MAX_VAL]; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I mentioned in one of my earlier questions that I'm reading book C++ Coding
Reading the book VS 2010 by John Sharp, it says that generics allows to
Reading a book (VS 2010), it says that commands (statements) in .NET Csharp cannot
I am reading a book about Java and it says that you can declare
I'm reading a book about Clean coding and there're sample code. The author says
I am reading some book and I have encountered a piece of code that
I'm reading the book Multithreading Applications in Win32 The book says return node->next will
While reading one book named Cracking the coding interview by Gayle Laakmann , i
I am reading book called C++ coding standard By Herb Sutter, Andrei Alexandrescu and
I remember reading in Douglas Crockford's Javascript the Good Parts book that there is

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.