This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

single bit twos complement

what do you expect the result to be?

typedef struct
{
  signed int bit:1;
} T_oddity;

T_oddity oddity;

int foobar( int arg )
{
  oddity.bit = arg;

  return oddity.bit;
}

void foochocolate ( void )
{
  // stuff

  foobar ( -1 );

  // stuff
}

Parents Reply Children
  • I can't see why the standard should need to contain any special paragraph. The special is if the architecture have two-complement numbers or not. Scaling two-complement numbers all the way to a single bit shouldn't need standard coverage.

    A signed two-complement number of only one bit is per definition -1 or 0. A 2-bit number would be -2..1. A 3-bit number would be -4..3.

    This is a very, very common mistake when people only writes "int" as type for their bit fields. Or maybe "char" if the compiler have signed characters. Then they try to figure out why if (s.mybit == 1)
    always fails.

  • thanks. i've never seen the mistake before. you are obviously a very wise old owl. that is a compliment ;)

    if i ever see it i will think of you.