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

  • Home
  • SEARCH
  • 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 6671329
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:22:32+00:00 2026-05-26T03:22:32+00:00

I am a new programmer in C/C++ having programmed in Java for quite a

  • 0

I am a new programmer in C/C++ having programmed in Java for quite a while. I am currently understanding some C code. Here I am seeing some macro definitions like:

/* Flags for ds_flags */ 
#define DSF_OVER        (1<<0)  
#define DSF_DISPLAY     (1<<1)    
#define DSF_CALLFLOW    (1<<2) 

I am not able to understand why do we have to define these macros in such a manner. What is the advantage gained in these rather than in defining like:

#define DSF_OVER        0
#define DSF_DISPLAY     1    
#define DSF_CALLFLOW    2
  • 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-26T03:22:33+00:00Added an answer on May 26, 2026 at 3:22 am

    Some times the position of the bits represent some bit operations like in your case:

    #define DSF_OVER        (1<<0)  is 1
    #define DSF_DISPLAY     (1<<1)  is 2  
    #define DSF_CALLFLOW    (1<<2)  is 4 (This is not 3)
    

    If you were to add a new item later, you will do it as

    #define DSF_OVER       1
    #define DSF_DISPLAY    2  
    #define DSF_CALLFLOW   4
    #define DSF_CALLNEW    5.
    

    You cant have a value 5 here since it is two bits enabled (101 in binary). To avoid such potential errors it is always safe to use macros using >>. It can’t produce a value of 5 (101) by error in when the next bit should be 1000 in binary.

    It is all about programming convenience to produce error free code.

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

Sidebar

Related Questions

New programmer here with only some minor Java experience trying my hand at writing
I am a C/C++ programmer, and I am currently playing with some Javascript code,
I'm a relatively new Java programmer and I'm having difficuly removing more than one
New to Android and Java really (I'm a Pascal programmer originally) and having a
I'm a new Python programmer who is having a little trouble using 'self' in
I'm a relatively new Java programmer coming from C++/STL, and am looking for a
HI I am a new java programmer (very new). What I want to do/test
I’m a new iPhone programmer I have created some small views without delegates.... If
I'm a pretty experienced Java programmer that's been doing quite a bit of Win32
I've programmed for a while in Java and .Net, but never really used C

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.