Move MIN, MAX, and CLAMP to macros.h

We shouldn't have to include the whole defs.h to get them.

* defs.h (MIN, MAX, CLAMP): Move ...
* macros.h: ... here.
This commit is contained in:
Eugene Syromiatnikov 2017-11-09 17:39:18 +01:00 committed by Dmitry V. Levin
parent f3d9348fd1
commit bb9673ba1d
2 changed files with 8 additions and 9 deletions

9
defs.h
View File

@ -75,15 +75,6 @@ const char *strerror(int);
extern char *stpcpy(char *dst, const char *src);
#endif
/* macros */
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define CLAMP(val, min, max) MIN(MAX(min, val), max)
/* Glibc has an efficient macro for sigemptyset
* (it just does one or two assignments of 0 to internal vector of longs).
*/

View File

@ -35,6 +35,14 @@
#define STRINGIFY(...) #__VA_ARGS__
#define STRINGIFY_VAL(...) STRINGIFY(__VA_ARGS__)
#ifndef MAX
# define MAX(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef MIN
# define MIN(a, b) (((a) < (b)) ? (a) : (b))
#endif
#define CLAMP(val, min, max) MIN(MAX(min, val), max)
#ifndef offsetofend
# define offsetofend(type_, member_) \
(offsetof(type_, member_) + sizeof(((type_ *)0)->member_))