]> git.ozlabs.org Git - ccan/blob - ccan/likely/_info
ccan: Correct some poor conventions in _info includes
[ccan] / ccan / likely / _info
1 #include "config.h"
2 #include <string.h>
3 #include <stdio.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  * With CCAN_LIKELY_DEBUG defined, it provides statistics for each
13  * likely()/unlikely() call (but note that this requires LGPL dependencies).
14  *
15  * License: CC0 (Public domain)
16  * Author: Rusty Russell <rusty@rustcorp.com.au>
17  *
18  * Example:
19  *      #include <ccan/likely/likely.h>
20  *      #include <stdio.h>
21  *
22  *      int main(int argc, char *argv[])
23  *      {
24  *              // This example is silly: the compiler knows exit() is unlikely.
25  *              if (unlikely(argc == 1)) {
26  *                      fprintf(stderr, "Usage: %s <args>...\n", argv[0]);
27  *                      return 1;
28  *              }
29  *              for (argc++; argv[argc]; argc++)
30  *                      printf("%s\n", argv[argc]);
31  *              return 0;
32  *      }
33  */
34 int main(int argc, char *argv[])
35 {
36         /* Expect exactly one argument */
37         if (argc != 2)
38                 return 1;
39
40         if (strcmp(argv[1], "depends") == 0) {
41 #ifdef CCAN_LIKELY_DEBUG
42                 printf("ccan/str\n");
43                 printf("ccan/htable\n");
44                 printf("ccan/hash\n");
45 #endif
46                 return 0;
47         }
48         if (strcmp(argv[1], "testdepends") == 0) {
49 #ifndef CCAN_LIKELY_DEBUG
50                 printf("ccan/str\n");
51                 printf("ccan/htable\n");
52                 printf("ccan/hash\n");
53 #endif
54                 return 0;
55         }
56         return 1;
57 }