modules.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2014 Freie Universität Berlin
3  * 2017 HAW-Hamburg
4  *
5  * This file is subject to the terms and conditions of the GNU Lesser
6  * General Public License v2.1. See the file LICENSE in the top level
7  * directory for more details.
8  */
9 
10 #pragma once
11 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
59 #define IS_ACTIVE(macro) __is_active(macro)
60 
70 #define IS_USED(module) IS_ACTIVE(module)
71 
75 /* Here a prefix "__PREFIX_WHEN_" is added to the macro. So if it was a 1 we
76  * have "__PREFIX_WHEN_1", and if it was not defined we have "__PREFIX_WHEN_".
77  */
78 #define __is_active(val) ___is_active(__PREFIX_WHEN_##val)
79 
80 /* With this placeholder we turn the original value into two arguments when the
81  * original value was defined as 1 (note the comma).
82  */
83 #define __PREFIX_WHEN_1 0,
84 
85 /* Here we add two extra arguments, that way the next macro can accept varargs.
86  *
87  * If the original macro was defined as 1, this will have three arguments
88  * (__take_second_arg(0, 1, 0, 0)), otherwise it will have two
89  * (__take_second_arg(__PREFIX_WHEN_ 1, 0, 0)). The third zero is there just to
90  * be compliant with C99, which states that when a function-like macro ends
91  * with ellipsis (...) it should be called with at least one argument for the
92  * variable list.
93  */
94 #define ___is_active(arg1_or_junk) __take_second_arg(arg1_or_junk 1, 0, 0)
95 
96 /* Finally, we just always take the second argument, which will be either 1
97  * (when three arguments are passed, i.e. macro was defined as 1) or 0 (when
98  * only two arguments are passed).
99  */
100 #define __take_second_arg(__ignored, val, ...) val
105 #ifdef __cplusplus
106 }
107 #endif
108