头文件宏定义

/* Guard C code in headers, while including them from C++ */
#ifdef  __cplusplus
# define G_BEGIN_DECLS  extern "C" {
# define G_END_DECLS    }
#else
# define G_BEGIN_DECLS
# define G_END_DECLS
#endif

#ifndef NULL
#  ifdef __cplusplus
#    define NULL        (0L)
#  else /* !__cplusplus */
#    define NULL        ((void*) 0)
#  endif /* !__cplusplus */
#endif

#ifndef FALSE
#define FALSE (0)
#endif

#ifndef TRUE
#define TRUE (!FALSE)
#endif

#undef MAX
#define MAX(a, b)  (((a) > (b)) ? (a) : (b))

#undef MIN
#define MIN(a, b)  (((a) < (b)) ? (a) : (b))

#undef ABS
#define ABS(a)   (((a) < 0) ? -(a) : (a))

#undef CLAMP
#define CLAMP(x, low, high)  (((x) > (high)) ? (high) : (((x) < (low)) ? (low) : (x)))


/* Count the number of elements in an array. The array must be defined
 * as such; using this with a dynamically allocated array will give
 * incorrect results.
 */
#define G_N_ELEMENTS(arr) (sizeof (arr) / sizeof ((arr)[0]))

#if !(defined (G_STMT_START) && defined (G_STMT_END))
#  define G_STMT_START  do
#  define G_STMT_END    while (0)
#endif

#define option_is_object(hoption) \
    ((hoption)?true:false)
    

#define g_return_val_if_fail(expr, val) \
    G_STMT_START { \
    if(!(expr)) return val; \
    }G_STMT_END

#define g_return_if_fail(expr) \
    G_STMT_START { \
    if (!(expr)) return; \
    }G_STMT_END



/************定义断言宏************/
#ifdef DEBUG
    void _Assert(char*, unsigned);
    #define ASSERT(f) \
    if (f) \
NULL; \
    else \
        _Assert(__FILE__, __LINE__)
#else
    #define ASSERT(f)
#endif

void _Assert(char* strFile, unsigned uLine)
{
    fflush(stdout);
    fprintf(stderr, "\nAssertion failed:%s, line %u\n", strFile, uLine);
    fflush(stderr);
    abort();
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值