qse/ase/macros.h

115 lines
3.3 KiB
C
Raw Normal View History

2004-12-18 09:16:31 +00:00
/*
2006-06-23 11:50:34 +00:00
* $Id: macros.h,v 1.34 2006-06-23 11:50:34 bacon Exp $
2004-12-18 09:16:31 +00:00
*/
2004-12-18 09:58:49 +00:00
#ifndef _XP_MACROS_H_
#define _XP_MACROS_H_
2004-12-18 09:16:31 +00:00
2004-12-18 09:58:49 +00:00
#include <xp/types.h>
2004-12-18 09:16:31 +00:00
2005-03-29 07:29:13 +00:00
#ifdef __cplusplus
2006-04-03 10:40:26 +00:00
/*#define XP_NULL ((xp_uint_t)0)*/
#define XP_NULL (0)
2005-03-29 07:29:13 +00:00
#else
#define XP_NULL ((void*)0)
#endif
2005-05-28 13:34:26 +00:00
#define XP_CHAR_EOF ((xp_cint_t)-1)
2004-12-18 09:16:31 +00:00
2004-12-18 09:58:49 +00:00
#define xp_sizeof(n) (sizeof(n))
#define xp_countof(n) (sizeof(n) / sizeof(n[0]))
2005-04-18 11:28:07 +00:00
#define xp_offsetof(type,member) ((xp_size_t)&((type*)0)->member)
2005-05-10 16:08:10 +00:00
#if defined(_WIN32) && defined(XP_CHAR_IS_WCHAR) && !defined(__LCC__)
2005-07-27 11:09:46 +00:00
#define xp_main wmain
2005-01-21 06:02:02 +00:00
#elif defined(XP_CHAR_IS_MCHAR)
2005-07-27 11:09:46 +00:00
#define xp_main main
2004-12-18 09:16:31 +00:00
#endif
2005-03-30 10:48:17 +00:00
#define XP_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1))
#define XP_TYPE_IS_UNSIGNED(type) (((type)0) < ((type)-1))
2005-03-30 07:26:38 +00:00
#define XP_TYPE_MAX(type) \
2005-03-30 10:21:33 +00:00
((XP_TYPE_IS_SIGNED(type)? (type)~((type)1 << (xp_sizeof(type) * 8 - 1)): (type)(~(type)0)))
2005-03-30 07:26:38 +00:00
#define XP_TYPE_MIN(type) \
2005-03-30 10:21:33 +00:00
((XP_TYPE_IS_SIGNED(type)? (type)((type)1 << (xp_sizeof(type) * 8 - 1)): (type)0))
2005-03-30 07:26:38 +00:00
2005-03-30 10:49:01 +00:00
#define XP_NUM_IS_POWOF2(x) (((x) & ((x) - 1)) == 0)
2005-07-30 05:11:39 +00:00
#define XP_SWAP(x,y,original_type,casting_type) \
do { \
x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \
y = (original_type)((casting_type)(y) ^ (casting_type)(x)); \
x = (original_type)((casting_type)(x) ^ (casting_type)(y)); \
} while (0)
2005-07-21 15:31:25 +00:00
#define XP_ABS(x) ((x) < 0? -(x): (x))
2005-03-30 10:48:17 +00:00
2004-12-18 09:58:49 +00:00
#define XP_LOOP_CONTINUE(id) goto __loop_ ## id ## _begin__;
#define XP_LOOP_BREAK(id) goto __loop_ ## id ## _end__;
#define XP_LOOP_BEGIN(id) __loop_ ## id ## _begin__: {
#define XP_LOOP_END(id) XP_LOOP_CONTINUE(id) } __loop_ ## id ## _end__:;
2004-12-18 09:16:31 +00:00
2005-04-02 13:14:33 +00:00
#define XP_REPEAT(n,blk) \
do { \
2005-04-02 15:36:02 +00:00
xp_size_t __xp_repeat_x1 = (xp_size_t)(n); \
2005-04-02 15:10:48 +00:00
xp_size_t __xp_repeat_x2 = __xp_repeat_x1 >> 4; \
__xp_repeat_x1 &= 15; \
2005-04-02 14:28:18 +00:00
while (__xp_repeat_x1-- > 0) { blk; } \
while (__xp_repeat_x2-- > 0) { \
blk; blk; blk; blk; blk; blk; blk; blk; \
blk; blk; blk; blk; blk; blk; blk; blk; \
} \
2005-04-02 13:14:33 +00:00
} while (0);
2006-05-06 12:52:36 +00:00
/* obsolete */
2005-05-02 11:14:59 +00:00
#define XP_MQUOTE(val) #val
2005-02-06 03:27:54 +00:00
#define XP_MCHAR(ch) ((xp_mchar_t)ch)
#define XP_MTEXT(txt) ((const xp_mchar_t*)txt)
2005-01-06 15:31:59 +00:00
2006-05-06 12:52:36 +00:00
/* new short form */
#define XP_MQ(val) #val
#define XP_MC(ch) ((xp_mchar_t)ch)
#define XP_MS(str) ((const xp_mchar_t*)str)
#define XP_MT(txt) (txt)
2005-01-17 03:12:56 +00:00
/* TODO: if the compiler doesn't have the built-in wchar_t support
* XP_WCHAR & XP_WTEXT must be defined differently.
2005-01-21 04:22:24 +00:00
#define XP_WCHAR(ch) ((xp_wchar_t)ch)
#define XP_WTEXT(txt) don't know yet... may have to call a function?
2005-01-17 03:12:56 +00:00
*/
2006-05-06 12:52:36 +00:00
/* obsolete */
2005-05-02 11:14:59 +00:00
#define XP_WQUOTE(val) ((const xp_char_t*)L###val)
2005-02-06 03:27:54 +00:00
#define XP_WCHAR(ch) ((xp_wchar_t)L##ch)
#define XP_WTEXT(txt) ((const xp_wchar_t*)L##txt)
2004-12-18 09:16:31 +00:00
2006-05-06 12:52:36 +00:00
/* new short form */
#define XP_WQ(val) ((const xp_char_t*)L###val)
#define XP_WC(ch) ((xp_wchar_t)L##ch)
#define XP_WS(str) ((const xp_wchar_t*)L##str)
#define XP_WT(txt) (L##txt)
2005-02-05 06:05:19 +00:00
#if defined(XP_CHAR_IS_MCHAR)
2006-05-06 12:52:36 +00:00
/* obsolete */
2005-02-05 06:05:19 +00:00
#define XP_CHAR(ch) XP_MCHAR(ch)
#define XP_TEXT(txt) XP_MTEXT(txt)
2005-05-02 11:14:59 +00:00
#define XP_QUOTE(val) XP_MQUOTE(val)
2006-05-06 12:52:36 +00:00
/* new short form */
#define XP_C(ch) XP_MC(ch)
#define XP_S(str) XP_MS(str)
#define XP_T(txt) XP_MT(txt)
#define XP_Q(val) XP_MQ(val)
2005-01-06 15:31:59 +00:00
#else
2006-05-06 12:52:36 +00:00
/* obsolete */
2005-02-05 06:05:19 +00:00
#define XP_CHAR(ch) XP_WCHAR(ch)
#define XP_TEXT(txt) XP_WTEXT(txt)
2005-05-02 11:14:59 +00:00
#define XP_QUOTE(val) XP_WQUOTE(val)
2006-05-06 12:52:36 +00:00
/* new short form */
#define XP_C(ch) XP_WC(ch)
#define XP_S(str) XP_WS(str)
#define XP_T(txt) XP_WT(txt)
#define XP_Q(val) XP_WQ(val)
2005-01-06 15:31:59 +00:00
#endif
2004-12-18 09:16:31 +00:00
#endif