3.16 Example 15

The next example is abbreviated from the original:

  5861 seek ()
       {
         int n[2];
         register *fp, t;
         fp = getf (u.u_ar0[R0]);
         ...........
         t = u.u_arg[1];
         switch (t) {

         case 1:
         case 4:
           n[0] =+ fp->f_offset[0];
           dpadd (n, fp->f_offset[1]);
           break;

         default:
           n[0] =+ fp->f_inode->i size0 & 0377;
           dpadd(n,fp->f_inode->i_size1);

         case 0:
         case 3:
           ;
         }
         ...........
       }

Note the array declaration for the two word array “n”, and the use of getf (which appeared in Example 4).

The “switch” statement makes a multiway branch depending on the value of the expression in parentheses. The individual parts have “case labels”:

Note the use of “break” as an escape to the next statement after the end of the “switch” statement. Without the “break”, the normal execution sequence would be followed within the “switch” statement.

Thus a “break” would normally be required at the end of the “default” actions. It has been omitted safely here because the only remaining cases actually have null actions associated with them.

The two non-trivial pairs of actions represent the addition of one 32 bit integer to another. The later versions of the “C” compiler will support “long” variables and make this sort of code much easier to write (and read).

Note also that in the expression

    fp->f_inode->i_size0

there are two levels of indirection.