MLib Reference Manual | ||||
---|---|---|---|---|
Top | Description |
#include <mlib.h> #define M_BEGIN_DECLS #define M_END_DECLS #define NULL #define MAX (a, b) #define MIN (a, b) #define ABS (a) #define CLAMP (x, low, high) #define M_N_ELEMENTS (arr) #define M_STMT_START #define M_STMT_END
#define M_BEGIN_DECLS
Used (along with M_END_DECLS) to bracket header files. If the compiler in use is a C++ compiler, adds extern "C" around the header.
#define M_END_DECLS
Used (along with M_BEGIN_DECLS) to bracket header files. If the compiler in use is a C++ compiler, adds extern "C" around the header.
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
Calculates the maximum of a and b.
|
a numeric value. |
|
a numeric value. |
Returns : |
the maximum of a and b. |
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
Calculates the minimum of a and b.
|
a numeric value. |
|
a numeric value. |
Returns : |
the minimum of a and b. |
#define ABS(a) (((a) < 0) ? -(a) : (a))
For example,
ABS(-10) is 10.
ABS(10) is also 10.
Calculates the absolute value of a. The absolute value is simply the number with any negative sign taken away.
|
a numeric value. |
Returns : |
the absolute value of a. |
#define CLAMP(x, low, high) (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))
For example,
CLAMP(5, 10, 15) is 10.
CLAMP(15, 5, 10) is 10.
CLAMP(20, 15, 25) is 20.
Ensures that x is between the limits set by low and high. If low is greater than high the result is undefined.
|
the value to clamp. |
|
the minimum value allowed. |
|
the maximum value allowed. |
Returns : |
the value of x clamped to the range between low and high. |
#define M_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))
Determines the number of elements in an array.
The array must be declared so the compiler knows its size at compile-time; this macro will not work on an array allocated on the heap, only static arrays or arrays on the stack.
|
the array |
# define M_STMT_START do
Used within multi-statement macros so that they can be used in places where only one statement is expected by the compiler.