added QSE_ALIGNOF().

This commit is contained in:
2011-11-17 16:07:35 +00:00
parent df28fde9ef
commit 1f9de59543
7 changed files with 49 additions and 31 deletions

View File

@ -119,7 +119,7 @@
#define QSE_SIZEOF(n) (sizeof(n))
/**
* The QSE_COUNTOF() macro gets the number elements in a array.
* The QSE_COUNTOF() macro returns the number elements in an array.
* The following code snippet should print 128.
* @code
* int x[128];
@ -129,16 +129,24 @@
#define QSE_COUNTOF(n) (sizeof(n)/sizeof(n[0]))
/**
* The QSE_OFFSETOF() macro get the offset of a fields from the beginning
* The QSE_OFFSETOF() macro returns the offset of a field from the beginning
* of a structure.
*/
#define QSE_OFFSETOF(type,member) ((qse_size_t)&((type*)0)->member)
#define QSE_OFFSETOF(type,member) \
((qse_size_t)&((type*)0)->member)
/**
* The QSE_ALIGNOF() macro returns the alignment size of a structure.
* Note that this macro may not work reliably depending on the type given.
*/
#define QSE_ALIGNOF(type) QSE_OFFSETOF(struct { qse_uint8_t d1; type d2 }, d2)
/*(sizeof(struct { qse_uint8_t d1; type d2 }) - sizeof(type))*/
/**
* The QSE_TYPE_IS_SIGNED() macro determines if a type is signed.
* @code
* printf ("%d\n", QSE_TYPE_IS_SIGNED(int));
* printf ("%d\n", QSE_TYPE_IS_SIGNED(unsigned int));
* printf ("%d\n", (int)QSE_TYPE_IS_SIGNED(int));
* printf ("%d\n", (int)QSE_TYPE_IS_SIGNED(unsigned int));
* @endcode
*/
#define QSE_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1))

View File

@ -19,13 +19,13 @@
*/
#if defined(__GNUC__)
#pragma pack(1)
# pragma pack(1)
#elif defined(__HP_aCC) || defined(__HP_cc)
#pragma PACK 1
# pragma PACK 1
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#pragma pack(push,1)
# pragma pack(push,1)
#elif defined(__DECC)
#pragma pack(push,1)
# pragma pack(push,1)
#else
#pragma pack(1)
# pragma pack(1)
#endif

View File

@ -19,13 +19,13 @@
*/
#if defined(__GNUC__)
#pragma pack(2)
# pragma pack(2)
#elif defined(__HP_aCC) || defined(__HP_cc)
#pragma PACK 2
# pragma PACK 2
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#pragma pack(push,2)
# pragma pack(push,2)
#elif defined(__DECC)
#pragma pack(push,2)
# pragma pack(push,2)
#else
#pragma pack(2)
# pragma pack(2)
#endif

View File

@ -19,13 +19,13 @@
*/
#if defined(__GNUC__)
#pragma pack()
# pragma pack()
#elif defined(__HP_aCC) || defined(__HP_cc)
#pragma PACK
# pragma PACK
#elif defined(_MSC_VER) || defined(__BORLANDC__)
#pragma pack(pop)
# pragma pack(pop)
#elif defined(__DECC)
#pragma pack(pop)
# pragma pack(pop)
#else
#pragma pack()
# pragma pack()
#endif