Table Of Contents
Previous Section Next Section

Program 105: Waving the Flag

One of the problems with cute tricks is that far too many programmers don't put in any comments that tell you what's going on. Here's a recreation of some code I found in the UNIX stty command. What's happening?

  1 #include <stdio.h>
  2
  3 int main()
  4 {
  5     int flags = 0x5;    // Some sample flags
  6
  7     printf("-parity\n" + ((flags & 0x1) != 0));
  8     printf("-break\n"  + ((flags & 0x2) != 0));
  9     printf("-xon\n"    + ((flags & 0x4) != 0));
 10     printf("-rts\n"    + ((flags & 0x8) != 0));
 11     return (0);
 12 }
 13

(Next Hint 301. Answer 108.)

Table Of Contents
Previous Section Next Section