From 1f9de595438f22872fb241d21c87fdd4a6edd695 Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Thu, 17 Nov 2011 16:07:35 +0000 Subject: [PATCH] added QSE_ALIGNOF(). --- qse/include/qse/macros.h | 18 +++++++++++++----- qse/include/qse/pack1.h | 10 +++++----- qse/include/qse/pack2.h | 10 +++++----- qse/include/qse/unpack.h | 10 +++++----- qse/lib/cmn/alg-rand.c | 20 ++++++++++++++++++++ qse/samples/cmn/fio02.c | 11 +---------- qse/samples/sed/sed01.c | 1 - 7 files changed, 49 insertions(+), 31 deletions(-) diff --git a/qse/include/qse/macros.h b/qse/include/qse/macros.h index 137f9cc1..2f13ef43 100644 --- a/qse/include/qse/macros.h +++ b/qse/include/qse/macros.h @@ -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)) diff --git a/qse/include/qse/pack1.h b/qse/include/qse/pack1.h index 1c3a2b8c..0f8668a4 100644 --- a/qse/include/qse/pack1.h +++ b/qse/include/qse/pack1.h @@ -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 diff --git a/qse/include/qse/pack2.h b/qse/include/qse/pack2.h index 66d256e5..5f6ca8ef 100644 --- a/qse/include/qse/pack2.h +++ b/qse/include/qse/pack2.h @@ -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 diff --git a/qse/include/qse/unpack.h b/qse/include/qse/unpack.h index 4653c4d0..85b5ccac 100644 --- a/qse/include/qse/unpack.h +++ b/qse/include/qse/unpack.h @@ -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 diff --git a/qse/lib/cmn/alg-rand.c b/qse/lib/cmn/alg-rand.c index 1bf5ad38..709e090f 100644 --- a/qse/lib/cmn/alg-rand.c +++ b/qse/lib/cmn/alg-rand.c @@ -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 . + */ + #include /* Park-Miller "minimal standard" 31 bit diff --git a/qse/samples/cmn/fio02.c b/qse/samples/cmn/fio02.c index 617225c3..140379e4 100644 --- a/qse/samples/cmn/fio02.c +++ b/qse/samples/cmn/fio02.c @@ -1,8 +1,6 @@ #include #include - #include -#include #define R(f) \ do { \ @@ -25,7 +23,7 @@ static int test1 (void) QSE_NULL, 0, file, - QSE_FIO_CREATE | QSE_FIO_EXCLUSIVE | QSE_FIO_TEMPORARY | QSE_FIO_READ | QSE_FIO_WRITE, + QSE_FIO_CREATE | QSE_FIO_EXCLUSIVE | QSE_FIO_TEMPORARY | QSE_FIO_READ | QSE_FIO_WRITE, QSE_FIO_RUSR|QSE_FIO_WUSR|QSE_FIO_RGRP|QSE_FIO_ROTH ); if (fio == QSE_NULL) @@ -81,13 +79,6 @@ static int test1 (void) 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); - return 0; } diff --git a/qse/samples/sed/sed01.c b/qse/samples/sed/sed01.c index 982f5191..ad2372b1 100644 --- a/qse/samples/sed/sed01.c +++ b/qse/samples/sed/sed01.c @@ -62,7 +62,6 @@ oops: return ret; } - int qse_main (int argc, qse_achar_t* argv[]) { return qse_runmain (argc, argv, sed_main);