]> git.ozlabs.org Git - ccan/blob - ccan/likely/_info
likely: new module
[ccan] / ccan / likely / _info
1 #include <string.h>
2 #include <stdio.h>
3 #include "config.h"
4
5 /**
6  * likely - macros for annotating likely/unlikely branches in the code
7  *
8  * Inspired by Andi Kleen's macros for the Linux Kernel, these macros
9  * help you annotate rare paths in your code for the convenience of the
10  * compiler and the reader.
11  *
12  * Licence: LGPL (2 or any later version)
13  *
14  * Example:
15  *      #include <ccan/likely/likely.h>
16  *      #include <stdio.h>
17  *
18  *      int main(int argc, char *argv[])
19  *      {
20  *              // This example is silly: the compiler knows exit() is unlikely.
21  *              if (unlikely(argc == 1)) {
22  *                      fprintf(stderr, "Usage: %s <args>...\n", argv[0]);
23  *                      return 1;
24  *              }
25  *              for (argc++; argv[argc]; argc++)
26  *                      printf("%s\n", argv[argc]);
27  *              return 0;
28  *      }
29  */
30 int main(int argc, char *argv[])
31 {
32         /* Expect exactly one argument */
33         if (argc != 2)
34                 return 1;
35
36         if (strcmp(argv[1], "depends") == 0) {
37                 printf("ccan/str\n");
38                 printf("ccan/hashtable\n");
39                 printf("ccan/hash\n");
40                 return 0;
41         }
42
43         return 1;
44 }