[prev] [index] [next]

C and Portability (cont)

More portability issues with C programs ...
  • arithmetic vs logical shifts for int quantities, e.g.

    int a;          ...  a = a >> 5;
    unsigned int a; ...  b = b >> 5;
    

  • layout of fields within structs e.g.

    struct x { char a; int b; } z; ...  &(z.b) - &(z.a)
    

  • byte ordering is different between architectures, e.g. int a = 5;

    [Diagram:Pic/byteorder.png]