]> git.ozlabs.org Git - ccan/blob - ccan/compiler/_info
compiler: header for compiler-specific wrappers.
[ccan] / ccan / compiler / _info
1 #include <string.h>
2 #include <stdio.h>
3 #include "config.h"
4
5 /**
6  * compiler - macros for common compiler extensions
7  *
8  * Abstracts away some compiler hints.  Currently these include:
9  * - UNLIKELY_FUNCTION_ATTRIBUTE
10  *      For functions not called in fast paths (aka. cold functions)
11  * - PRINTF_ATTRIBUTE
12  *      For functions which take printf-style parameters.
13  * - IDEMPOTENT_ATTRIBUTE
14  *      For functions which return the same value for same parameters.
15  * - NEEDED_ATTRIBUTE
16  *      For functions and variables which must be emitted even if unused.
17  * - UNNEEDED_ATTRIBUTE
18  *      For functions and variables which need not be emitted if unused.
19  * - IS_COMPILE_CONSTANT
20  *      For using different tradeoffs for compiletime vs runtime evaluation.
21  *
22  * Licence: LGPL (3 or any later version)
23  * Author: Rusty Russell <rusty@rustcorp.com.au>
24  *
25  * Example:
26  *      #include <ccan/compiler/attributs.h>
27  *      #include <stdio.h>
28  *      #include <stdarg.h>
29  *
30  *      // Example of a (slow-path) logging function.
31  *      static int log_threshold = 2;
32  *      static void UNLIKELY_FUNCTION_ATTRIBUTE PRINTF_ATTRIBUTE(2,3)
33  *              logger(int level, const char *fmt, ...)
34  *      {
35  *              va_list ap;
36  *              va_start(ap, fmt);
37  *              if (level >= log_threshold)
38  *                      vfprintf(stderr, fmt, ap);
39  *              va_end(ap);
40  *      }
41  *
42  *      int main(int argc, char *argv[])
43  *      {
44  *              if (argc != 1) {
45  *                      logger(3, "Don't want %i arguments!\n", argc-1);
46  *                      return 1;
47  *              }
48  *              return 0;
49  *      }
50  */
51 int main(int argc, char *argv[])
52 {
53         /* Expect exactly one argument */
54         if (argc != 2)
55                 return 1;
56
57         if (strcmp(argv[1], "depends") == 0) {
58                 return 0;
59         }
60
61         return 1;
62 }