Norman James | 6a58a27 | 2015-10-07 14:34:16 -0500 | [diff] [blame] | 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 | * // Outputs "Initialized 32 values" |
| 16 | * #include <ccan/array_size/array_size.h> |
| 17 | * #include <stdlib.h> |
| 18 | * #include <stdio.h> |
| 19 | * |
| 20 | * // We currently use 32 random values. |
| 21 | * static unsigned int vals[32]; |
| 22 | * |
| 23 | * int main(void) |
| 24 | * { |
| 25 | * unsigned int i; |
| 26 | * for (i = 0; i < ARRAY_SIZE(vals); i++) |
| 27 | * vals[i] = random(); |
| 28 | * printf("Initialized %u values\n", i); |
| 29 | * return 0; |
| 30 | * } |
| 31 | * |
| 32 | * License: CC0 (Public domain) |
| 33 | * Author: Rusty Russell <rusty@rustcorp.com.au> |
| 34 | */ |
| 35 | int main(int argc, char *argv[]) |
| 36 | { |
| 37 | if (argc != 2) |
| 38 | return 1; |
| 39 | |
| 40 | if (strcmp(argv[1], "depends") == 0) { |
| 41 | printf("ccan/build_assert\n"); |
| 42 | return 0; |
| 43 | } |
| 44 | |
| 45 | return 1; |
| 46 | } |