]> git.ozlabs.org Git - ccan/blob - ccan/array_size/_info.c
Finally, ARRAY_SIZE!
[ccan] / ccan / array_size / _info.c
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  *      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  * Licence: LGPL (2 or any later version)
29  */
30 int main(int argc, char *argv[])
31 {
32         if (argc != 2)
33                 return 1;
34
35         if (strcmp(argv[1], "depends") == 0) {
36                 printf("ccan/build_assert\n");
37                 return 0;
38         }
39
40         return 1;
41 }