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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:05:50+00:00 2026-05-15T20:05:50+00:00

Possible Duplicates: What does ‘: number’ after a struct field mean? What does ‘unsigned

  • 0

Possible Duplicates:
What does ‘: number’ after a struct field mean?
What does ‘unsigned temp:3’ means

I hate to ask this type of question, but it’s really bugging me, so I will ask:

What is the function of the : operator in the code below?

#include <stdio.h>

struct microFields
{
  unsigned int addr:9;
  unsigned int cond:2;
  unsigned int wr:1;
  unsigned int rd:1;
  unsigned int mar:1;
  unsigned int alu:3;
  unsigned int b:5;
  unsigned int a:5;
  unsigned int c:5;
};

union micro
{
  unsigned int microCode;
  microFields code;
};

int main(int argc, char* argv[])
{
  micro test;
  return 0;
} 

If anyone cares at all, I pulled this code from the link below:
http://www.cplusplus.com/forum/beginner/15843/

I would really like to know because I know I have seen this before somewhere, and I want to understand it for when I see it again.

  • 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-15T20:05:51+00:00Added an answer on May 15, 2026 at 8:05 pm

    They’re bit-fields, an example being that unsigned int addr:9; creates an addr field 9 bits long.

    It’s commonly used to pack lots of values into an integral type. In your particular case, it defining the structure of a 32-bit microcode instruction for a (possibly) hypothetical CPU (if you add up all the bit-field lengths, they sum to 32).

    The union allows you to load in a single 32-bit value and then access the individual fields with code like (minor problems fixed as well, specifically the declarations of code and test):

    #include <stdio.h>
    
    struct microFields {
        unsigned int addr:9;
        unsigned int cond:2;
        unsigned int wr:1;
        unsigned int rd:1;
        unsigned int mar:1;
        unsigned int alu:3;
        unsigned int b:5;
        unsigned int a:5;
        unsigned int c:5;
    };
    
    union micro {
        unsigned int microCode;
        struct microFields code;
    };
    
    int main (void) {
        int myAlu;
        union micro test;
        test.microCode = 0x0001c000;
        myAlu = test.code.alu;
        printf("%d\n",myAlu);
        return 0;
    }
    

    This prints out 7, which is the three bits making up the alu bit-field.

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

Sidebar

Related Questions

Possible Duplicate: What does ‘unsigned temp:3’ means I just found this code in a
Possible Duplicates: What does the ‘k’ prefix indicate in Apple’s APIs? Lower case “k”
Possible Duplicate: Where does ‘Hello world’ come from? What was the first Hello World
Possible Duplicate: Where does ‘Hello world’ come from? Hello world! is the most commonly
Possible Duplicates: Are PHP short tags acceptable to use? What does “<?=” mean when
Possible Duplicates: What does this expression mean “!!” What does the !! operator (double
Possible Duplicates: In Javascript, what does it mean when there is a logical operator
Possible Duplicates: Reference - What does this symbol mean in PHP? what do “=&”
Possible Duplicates: What does “=>” mean in PHP? Reference - What does this symbol
Possible Duplicate: What does “DateTime?” mean in C#? What does the ? mean after

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.