Question: I am trying to clearly understand the behaviour of the shift operators (especially for the boundary cases), so I devised a little test written in C++.

```
    int a = odd_value; //321 in my case but it should not matter (the last bit to be 1)
    print(0, a);

    a = a << 31; // (this gives a segmentation fault, as normal because it tries the sign bit becomes 1 but all the other bits are 0).
    print(0, a); //the segmentation fault happens here - it prints the minimum integer value and then gives the fault
    a = (a << 1) + 1; // but if then I do this, shouldn't it set a to -1 ??
    print(a); //gives 0

   void print(int stackCallIndex, int nb)
   {
     if(nb)
     {
        print(++stackCallIndex, nb >> 1);
        if(nb & 1) printf("%d", 1);
        else       printf("%d", 0);

        if(stackCallIndex % 8 == 0) printf(" ");
     }
   }

```

Answer: 
If you want the *standard* behavior, then it's undefined. According to [expr.shift]:

> 
> The value of `E1 << E2` is `E1` left-shifted `E2` bit positions; vacated bits are zero-filled. If `E1` has an unsigned
>  type, [...]. Otherwise, if `E1` has a signed type and non-negative value, and `E1`×`2`E2 is representable in the corresponding unsigned type of the result type, then that value, converted to the result type, is the
>  resulting value; otherwise, the behavior is undefined.
> 
> 
> 

Any (odd number > 1) x 231 is not representable by `uint32_t`, so the behavior is undefined. Your compiler apparently chooses to implement this as a segmentation fault, which is perfectly conforming behavior (edit: er, at least it would be, if that were where it is happening). 

A more typical approach would be just to let bits "fall off" the end. That is, `a << 31` for an odd number would become `0x80000000`. But even in that case, another left-shift of 1 would result in `0`, so you'd have to subtract 1 to get `-1`, not add `1`.
When I try that I get -214783648 which is the smallest known value in integer... this means that you are making an integer bigger than the allowed range that's why in your case you get a segmentation fault...