]> git.ozlabs.org Git - ccan/blob - ccan/array_size/_info
gitify the tree, especially the web makefile.
[ccan] / ccan / array_size / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * array_size - routine for safely deriving the size of a visible array.
7  *
8  * This provides a simple ARRAY_SIZE() macro, which (given a good compiler)
9  * will also break compile if you try to use it on a pointer.
10  *
11  * This can ensure your code is robust to changes, without needing a gratuitous
12  * macro or constant.
13  *
14  * Example:
15  *      #include <ccan/array_size/array_size.h>
16  *      #include <stdlib.h>
17  *
18  *      // We currently use 32 random values.
19  *      static unsigned int vals[32];
20  *
21  *      static void init_values(void)
22  *      {
23  *              unsigned int i;
24  *              for (i = 0; i < ARRAY_SIZE(vals); i++)
25  *                      vals[i] = random();
26  *      }
27  *
28  * License: LGPL (2 or any later version)
29  * Author: Rusty Russell <rusty@rustcorp.com.au>
30  */
31 int main(int argc, char *argv[])
32 {
33         if (argc != 2)
34                 return 1;
35
36         if (strcmp(argv[1], "depends") == 0) {
37                 printf("ccan/build_assert\n");
38                 return 0;
39         }
40
41         return 1;
42 }