macros.h revision 220a5d63606d4e0d0db2ccdd810b2191fc256146
#ifndef __MACROS_H
#define __MACROS_H
/* several useful macros, mostly from glib.h */
#ifndef NULL
# define NULL ((void *)0)
#endif
#ifndef FALSE
# define FALSE (0)
#endif
#ifndef TRUE
#endif
#define BITS_IN_UINT (CHAR_BIT * sizeof(unsigned int))
files that are included after this file generating tons of warnings. */
#define I_MIN(a, b) (((a) < (b)) ? (a) : (b))
#define I_MAX(a, b) (((a) > (b)) ? (a) : (b))
sizeof(size_t) == sizeof(void *) and they're both the largest datatypes
that are allowed to be used. so, long long isn't safe with these. */
#define POINTER_CAST(i) \
((void *) ((char *) NULL + (i)))
#define POINTER_CAST_TO(p, type) \
/* Define VA_COPY() to do the right thing for copying va_list variables.
config.h may have already defined VA_COPY as va_copy or __va_copy. */
#ifndef VA_COPY
(defined (_CALL_SYSV) || defined (_WIN32))
# elif defined (VA_COPY_AS_ARRAY)
# else /* va_list is a pointer */
# endif /* va_list is a pointer */
#endif
/* Provide convenience macros for handling structure
* fields through their offsets.
*/
((void *) ((char *) (struct_p) + (long) (struct_offset)))
/* Provide simple macro statement wrappers (adapted from Perl):
STMT_START { statements; } STMT_END;
can be used as a single statement, as in
if (x) STMT_START { ... } STMT_END; else ...
For gcc we will wrap the statements within `({' and `})' braces.
For SunOS they will be wrapped within `if (1)' and `else (void) 0',
and otherwise within `do' and `while (0)'. */
#if !(defined (STMT_START) && defined (STMT_END))
# if defined (__GNUC__) && !defined (__cplusplus) && \
!defined (__STRICT_ANSI__) && !defined (PEDANTIC)
# define STMT_START (void)(
# define STMT_END )
# else
# define STMT_START if (1)
# define STMT_END else (void)0
# else
# define STMT_START do
# define STMT_END while (0)
# endif
# endif
#endif
/* Provide macros to feature the GCC function attribute. */
# define __attrs_used__
# define __attr_format_arg__(arg_idx) \
# define __attr_const__ __attribute__((const))
# if __GNUC__ > 3
/* GCC 4.0 and later */
# else
# define __attr_warn_unused_result__
# define __attr_sentinel__
# endif
#else
# define __attr_format_arg__(arg_idx)
# define __attr_unused__
# define __attr_noreturn__
# define __attr_const__
# define __attr_unused__
# define __attr_sentinel__
#endif
/* C99-style struct member definitions */
#else
#endif
/* Macros to provide type safety for callback functions' context parameters */
#ifdef __GNUC__
# define CONTEXT_TYPE_SAFETY
#endif
#ifdef CONTEXT_TYPE_SAFETY
#else
#endif
/* Wrap the gcc __PRETTY_FUNCTION__ and __FUNCTION__ variables with
macros, so we can refer to them as strings unconditionally. */
#ifdef __GNUC__
# define GNUC_FUNCTION __FUNCTION__
# define GNUC_PRETTY_FUNCTION __PRETTY_FUNCTION__
#else
# define GNUC_FUNCTION ""
# define GNUC_PRETTY_FUNCTION ""
#endif
/* Provide macros for error handling. */
#ifdef DISABLE_ASSERTS
if (!(expr)) \
i_panic("file %s: line %d (%s): assertion failed: (%s)", \
__FILE__, \
__LINE__, \
#else /* !__GNUC__ */
if (!(expr)) \
i_panic("file %s: line %d: assertion failed: (%s)", \
__FILE__, \
__LINE__, \
#endif
#define i_unreached() \
#endif