/* * util.h * * Created on: Feb 26, 2023 * Author: Daniel Peter Chokola */ #ifndef UTIL_H_ #define UTIL_H_ /* Definitions */ #ifdef __GNUC__ # define UNUSED __attribute__((unused)) #else # define UNUSED #endif #define return_if_fail(cond) \ if(!(cond)) { return; } #define return_val_if_fail(cond, val) \ if(!(cond)) { return (val); } #define return_null_if_fail(cond) return_val_if_fail((cond), NULL) /* MIN() and MAX() */ #ifdef __GNUC__ # if (__GNUC__ > 4) || ((__GNUC__ == 4) && (__GNUC_MINOR__ >= 9)) /* prevent double evaluation */ # define MIN(a,b) \ __extension__({ __auto_type _a = (a); \ __auto_type _b = (b); \ _a < _b ? _a : _b; }) # define MAX(a,b) \ __extension__({ __auto_type _a = (a); \ __auto_type _b = (b); \ _a > _b ? _a : _b; }) # else /* typesafety but double evaluation is possible */ # define MIN(a,b) \ __extension__({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a < _b ? _a : _b; }) # define MAX(a,b) \ __extension__({ __typeof__ (a) _a = (a); \ __typeof__ (b) _b = (b); \ _a > _b ? _a : _b; }) # endif #else /* no typesafety and double evaluation is possible */ # define MIN(a,b) ((a) < (b) ? (a) : (b)) # define MAX(a,b) ((a) > (b) ? (a) : (b)) #endif #endif /* UTIL_H_ */