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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:29:24+00:00 2026-05-15T18:29:24+00:00

(Question is related to my previous questions here , here , here , and

  • 0

(Question is related to my previous questions here, here, here, and here).

I am maintaining a very old application that was ported years ago from DOS to Windows, but a lot of the old C conventions still carry forward.

The one particular convention is a setBit and clrBit macro:

#ifndef setBit
#define setBit(word, mask) word |= mask
#endif

#ifndef clrBit
#define clrBit(word, mask) word &= ~mask
#endif

I found that I could declare a variable as an enum type and set my variable equal to the one of the enumerated values that are defined.

enum SystemStatus
{
    SYSTEM_ONLINE                = BIT0,
    SYSTEM_STATUS2               = BIT1,
    SYSTEM_STATUS3               = BIT2,
    SYSTEM_STATUS4               = BIT3
};

With BIT0 = 0x00000001, BIT1 = 0x00000002, etc.

SystemStatus systemStatus;

systemStatus = SYSTEM_ONLINE

In your opinion, is using the setBit and clrBit macros more C like or C++ like – and would it be better to simply declare variables as an enumerated type and get rid of all the old setBit/clrBit stuff?

  • 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-05-15T18:29:25+00:00Added an answer on May 15, 2026 at 6:29 pm

    I think you’re confusing the purposes. The enum is about setting up values to use as flags. setBit and clrBit are about operating on data. That data might happen to be a flag, but that’s really the only relationship between the two ideas.

    That being said, macros are certainly NOT the C++ way of doing things. You would use inline functions instead. For example:

    template<typename T>
    inline T& setBit(T& word, T mask) { return word |= mask; }
    
    template<typename T>
    inline T& clrBit(T& word, T mask) { return word &= ~mask; }
    

    Edit to fend off nitpickers:

    This is just an example of how you could implement the functions. You don’t need to use templates, you can use two template parameters instead of 1, you can use a void function or values instead of references if you want, (though then it would lose some of the original semantics). The main point is to get the benefits of type safety which you won’t find in macros (among many other downsides of macros). http://www.parashift.com/c++-faq-lite/inline-functions.html#faq-9.5

    Edit: Here’s a void, non-template version for comparison

    inline void setBit(unsigned int word, unsigned int mask) { word |= mask; }
    
    inline void clrBit(unsigned int word, unsigned int mask) { word &= ~mask; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.