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