Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
typedef struct time_day {
  unsigned h1 : 2;	{0:2}
  unsigned h2 
  unsigned m1 
  unsigned m2 
  unsigned s1 
  unsigned s2 
  unsigned f1 
  unsigned f2 
  unsigned f3
  {0:9} {0:5) {0:9) {0:5) {0:9) {0:9} {0:9} {0:9}
} TIME_DAY;	/* 32 bits total */

...

Code Block
f3	f2	f1	s2	s1	m2	ml	h2      h1

Most other implementations are "left-to-right":

...

Code Block
#include "time_day.h"
struct time_day last_msec = {2, 3, 5, 9, 5, 9, 9, 9, 9};
 /* initializes last_msec to the last millisecond of the day. */
struct time_day now;

/* ... */
if (now.h1 == 0 || (now.h1 == 1 && now.h2 < 2))

tests whether now is less than noon.
If we wish to use the TIME_DAY structure for an information-hiding purpose, so that it could be changed without affecting the programs that use it, we should employ the "leading-underscore" convention mentioned earlier in Section 6.2 :

...

The TIME_DAY example illustrates the use of bit-fields nicely, but there are numerous other ways to represent time-of-day.

...