From: Martin Mares Date: Wed, 7 Mar 2001 13:34:58 +0000 (+0000) Subject: Added a couple of useful macros: MIN, MAX, CLAMP, ARRAY_SIZE. X-Git-Tag: holmes-import~1518 X-Git-Url: http://mj.ucw.cz/gitweb/?a=commitdiff_plain;h=948bf112e3b3aba44e2dabfd0fa47724097166d3;p=libucw.git Added a couple of useful macros: MIN, MAX, CLAMP, ARRAY_SIZE. Removed NULL as it's already defined in config.h. --- diff --git a/lib/lib.h b/lib/lib.h index 9283e7aa..eb079dcd 100644 --- a/lib/lib.h +++ b/lib/lib.h @@ -19,16 +19,19 @@ #define _GNU_SOURCE -#ifndef NULL -#define NULL ((void *)0) -#endif - /* Ugly structure handling macros */ #define OFFSETOF(s, i) ((unsigned int)&((s *)0)->i) #define SKIP_BACK(s, i, p) ((s *)((char *)p - OFFSETOF(s, i))) #define ALIGN(s, a) (((s)+a-1)&~(a-1)) +/* Some other macros */ + +#define MIN(a,b) (((a)<(b))?(a):(b)) +#define MAX(a,b) (((a)>(b))?(a):(b)) +#define CLAMP(x,min,max) ({ int _t=x; (_t < min) ? min : (_t > max) ? max : _t; }) +#define ARRAY_SIZE(a) (sizeof(a)/sizeof(*(a))) + /* Temporary Files */ #define TMP_DIR "tmp"