4 * argcheck - macros to check arguments at runtime
6 * This code provides some macros to check arguments for valid value ranges.
7 * Consider this a mild version of assert(3), because all it does is to log
8 * a message and continue.
10 * These macros don't replace error handling, but they are useful in
11 * situations where an error is unexpected but not common, i.e.
12 * "this shouldn't happen but if it does let me know".
14 * argcheck's error messages can be disabled by defining
15 * ARGCHECK_DISABLE_LOGGING before including the header file. The conditions
16 * will continue to evaluate but no error messages will be generated. It is thus
17 * safe to use argcheck macros inside if conditions.
19 * By default, argcheck prints to fprintf(stderr). That can be changed by
20 * defining argcheck_log to a custom log function. See argcheck_log_() for the
21 * function signature. If ARGCHECK_DISABLE_LOGGING is defined, the custom log
22 * function is not called.
26 * #include <ccan/argcheck/argcheck.h>
28 * enum state { S1, S2, S3 };
30 * static int some_state_machine(enum state s) {
33 * argcheck_int_range(s, S1, S3);
36 * case S1: b = 8; break;
37 * case S2: b = 9; break;
38 * case S3: b = 88; break;
46 * int main(int argc, char *argv[]) {
49 * if (!argcheck_int_gt(argc, 1))
52 * return some_state_machine(a);
55 * Author: Peter Hutterer <peter.hutterer@who-t.net>
56 * Maintainer: Peter Hutterer <peter.hutterer@who-t.net>
60 int main(int argc, char *argv[])
62 /* Expect exactly one argument */
66 if (strcmp(argv[1], "depends") == 0) {
67 printf("ccan/likely\n");
68 printf("ccan/compiler\n");