1. ## 2 questions about bit fields and variable handling

1 question:

Code:
```#include <stdio.h>

struct foo{
int a:4;
};

int main(void){
struct foo s;

s.a=10;

printf("%d\n",s.a);
getchar();

return 0;

}```
10 in binary is 1010, but this gives me output -6, shouldn't it be -2?

the forth digit of 10 in binary is 1 that means the result will be <0, the remaining part of this is 010 which is 2, so why does it give me -6 instead of -2?

2 question:

Code:
```int x=0;
int y=++x; // y=1 and x=1

int x=0;
int y=x++; //y=0 and x=1```
but if we have

Code:
```y=0;
x=y==++y;```
why is x here 1??? I mean 0!=1 right? I can't get it

also
Code:
`x=y==y++;`
here x is 0?? Why?

2. ok i understand why it gives -6 now

because we have 4 digits and the forth one is 1(<0) then it takes all the digits and changes them from 1010 to 0101 and adds 1 to the end so 0110

am i right? I still can't figure out the second one though

hmmm...

Code:
```y=0;
x=y==++y;```
What happens is this
1) y += 1
2) y == y which is 1 == 1, true
3) x = true (the compiler gives true == 1)

Code:
`x=y==y++;`
I would guess you would get 1 again. But maybe you compiler does something like
1) a = y, b = y++
2) a == b
3) a = y = 0, b = y++ = 1. Thus a != b
In the previous one it would do the same, but
1) y+= 1
2) a = b
3) a = y = 1, b = y = 1. Thus a == b
since ++y will happen first

The problem with the second is that it could also do
3) b = y++ = 1, a = y = 1. Thus a == b
so it is ambiguous
It could also do
1) a = y, b = y
2) y += 1
3) a == b, true
or switch 2) with 3) in which case again true

The reason of a and b is because it needs temporarily variables for the result of the left and right side. The general idea is that you have something like foo() == boo() so temporarily variables are need for results.

These are ofcourse assumptions. You realise that in a real program you should never use code like that no matter what.

4. thanks a lot

5. > What happens is this
No, that is "may", not "is".
It may also blow up your computer, because the whole thing is undefined.
Expressions

Whether it's the pre or post form doesn't make it any less undefined.