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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:24:18+00:00 2026-06-06T22:24:18+00:00

I have some code here that uses bitsets to store many 1 bit values

  • 0

I have some code here that uses bitsets to store many 1 bit values into a char.

Basically

struct BITS_8 {
  char _1:1;
  (...)
  char _8:1;
}

Now i was trying to pass one of these bits as a parameter into a function

void func(char bit){
  if(bit){
    // do something
  }else{
    // do something else
  }
}

// and the call was
struct BITS_8 bits;
// all bits were set to 0 before
bits._7 = 1;
bits._8 = 0;
func(bits._8);

The solution was to single the bit out when calling the function:

func(bits._8 & 0x80);

But i kept going into //do something because other bits were set. I was wondering if this is the correct behaviour or if my compiler is broken. The compiler is an embedded compiler that produces code for freescale ASICs.

EDIT: 2 mistakes: the passing of the parameter and that bits._8 should have been 0 or else the error would make no sense.

Clarification

I am interested in what the standard has to say about the assignment

struct X{
   unsigned int k:6;
   unsigned int y:1;
   unsigned int z:1;
}

X x;
x.k = 0;
x.y = 1;
x.z = 0;

char t = X.y;

Should now t contain 1 or b00000010?

  • 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-06T22:24:19+00:00Added an answer on June 6, 2026 at 10:24 pm

    Ok, it was a compiler bug. I wrote the people that produce the compiler and they confirmed it. It only happens if you have a bitfield with an inline function.

    Their recommended solution is (if i don’t want to wait for a patch)

    func((char)bits._8));
    

    The other answers are right about the correct behaviour. Still i’m marking this one as the answer as it is the answer to my problem.

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

Sidebar

Related Questions

I have some code that is using SyncEnumerator. As you can see here ,
So I have some PHP code that looks like: $message = 'Here is the
Just some example code here, but I have lists of strings that I want
I have some code that uses xsl and xml. The Xml control is on
I have some code that uses the stristr function to extract data I need.
I have some code that uses dispatchEvent to simulate clicks and the same exact
I have some code that uses subprocess to look at the logs from a
i have some code examples I am working to implement that uses the type
I have some code i'd like to refactor that uses a C# iterator (ie
I have some code that uses a form.submit() to open up another window when

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.