added QSE_ALIGNOF().

This commit is contained in:
hyung-hwan 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)) #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. * The following code snippet should print 128.
* @code * @code
* int x[128]; * int x[128];
@ -129,16 +129,24 @@
#define QSE_COUNTOF(n) (sizeof(n)/sizeof(n[0])) #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. * 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. * The QSE_TYPE_IS_SIGNED() macro determines if a type is signed.
* @code * @code
* printf ("%d\n", QSE_TYPE_IS_SIGNED(int)); * printf ("%d\n", (int)QSE_TYPE_IS_SIGNED(int));
* printf ("%d\n", QSE_TYPE_IS_SIGNED(unsigned int)); * printf ("%d\n", (int)QSE_TYPE_IS_SIGNED(unsigned int));
* @endcode * @endcode
*/ */
#define QSE_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1)) #define QSE_TYPE_IS_SIGNED(type) (((type)0) > ((type)-1))

View File

@ -1,3 +1,23 @@
/*
* $Id$
*
Copyright 2006-2011 Chung, Hyung-Hwan.
This file is part of QSE.
QSE is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of
the License, or (at your option) any later version.
QSE is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with QSE. If not, see <http://www.gnu.org/licenses/>.
*/
#include <qse/cmn/alg.h> #include <qse/cmn/alg.h>
/* Park-Miller "minimal standard" 31 bit /* Park-Miller "minimal standard" 31 bit

View File

@ -1,8 +1,6 @@
#include <qse/cmn/fio.h> #include <qse/cmn/fio.h>
#include <qse/cmn/stdio.h> #include <qse/cmn/stdio.h>
#include <string.h> #include <string.h>
#include <locale.h>
#define R(f) \ #define R(f) \
do { \ do { \
@ -81,13 +79,6 @@ static int test1 (void)
int main () int main ()
{ {
setlocale (LC_ALL, "");
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
qse_printf (QSE_T("Set the environment LANG to a Unicode locale such as UTF-8 if you see the illegal XXXXX errors. If you see such errors in Unicode locales, this program might be buggy. It is normal to see such messages in non-Unicode locales as it uses Unicode data\n"));
qse_printf (QSE_T("--------------------------------------------------------------------------------\n"));
R (test1); R (test1);
return 0; return 0;
} }

View File

@ -62,7 +62,6 @@ oops:
return ret; return ret;
} }
int qse_main (int argc, qse_achar_t* argv[]) int qse_main (int argc, qse_achar_t* argv[])
{ {
return qse_runmain (argc, argv, sed_main); return qse_runmain (argc, argv, sed_main);