diff options
author | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2012-06-25 16:50:38 +0000 |
---|---|---|
committer | vlefevre <vlefevre@280ebfd0-de03-0410-8827-d642c229c3f4> | 2012-06-25 16:50:38 +0000 |
commit | 35bde4fc99e73c78133e342257d07986d9d8d6b3 (patch) | |
tree | fd367896ecce2ead43dd001f3887caffd5ebba60 /src/mpfr-sassert.h | |
parent | 8dc9716fc2e3f8d4d945fbf7ef02b59affd0c2c9 (diff) | |
download | mpfr-35bde4fc99e73c78133e342257d07986d9d8d6b3.tar.gz |
Added Static Assertion support (modified patch from Patrick).
* Added src/mpfr-sassert.h: implementation of static assertions.
* src/mpfr-impl.h: include "mpfr-sassert.h".
* acinclude.m4: test whether static assertions are supported.
git-svn-id: svn://scm.gforge.inria.fr/svn/mpfr/trunk@8241 280ebfd0-de03-0410-8827-d642c229c3f4
Diffstat (limited to 'src/mpfr-sassert.h')
-rw-r--r-- | src/mpfr-sassert.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/mpfr-sassert.h b/src/mpfr-sassert.h new file mode 100644 index 000000000..63f30f1f1 --- /dev/null +++ b/src/mpfr-sassert.h @@ -0,0 +1,64 @@ +/* MPFR internal header related to Static Assertions + +Copyright 2012 Free Software Foundation, Inc. +Contributed by the AriC and Caramel projects, INRIA. + +This file is part of the GNU MPFR Library. + +The GNU MPFR Library 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. + +The GNU MPFR Library 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 the GNU MPFR Library; see the file COPYING.LESSER. If not, see +http://www.gnu.org/licenses/ or write to the Free Software Foundation, Inc., +51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. */ + +#ifndef __MPFR_STATIC_ASSERT_H__ +#define __MPFR_STATIC_ASSERT_H__ + +/* How to use: + =========== + MPFR_DECL_STATIC_ASSERT: + + to check a condition at compile time within the declaration section. + MPFR_STAT_STATIC_ASSERT: + + to check a condition at compile time within the statement section. +*/ + +#ifdef MPFR_USE_STATIC_ASSERT + +/* C11 version */ +# if defined (__STDC_VERSION__) +# if (__STDC_VERSION__ >= 201112L) +# define MPFR_DECL_STATIC_ASSERT(c) _Static_assert((c), #c ) +# define MPFR_STAT_STATIC_ASSERT(c) _Static_assert((c), #c ) +# endif +# endif + +/* Default version which should be compatible with nearly all compilers */ +# if !defined(MPFR_DECL_STATIC_ASSERT) +# define MPFR_ASSERT_CAT(a,b) MPFR_ASSERT_CAT_(a,b) +# define MPFR_ASSERT_CAT_(a,b) a ## b +# define MPFR_STAT_STATIC_ASSERT(c) do { \ + typedef enum { MPFR_ASSERT_CAT(MPFR_STATIC_ASSERT_CONST_,__LINE__) = !(c) } \ + MPFR_ASSERT_CAT(MPFR_ASSERT_,__LINE__)[!!(c) ? 1 : -1]; } while (0) +# define MPFR_DECL_STATIC_ASSERT(c) \ + typedef enum { MPFR_ASSERT_CAT(MPFR_STATIC_ASSERT_CONST_,__LINE__) = !(c) } \ + MPFR_ASSERT_CAT(MPFR_ASSERT_,__LINE__)[!!(c) ? 1 : -1]; +# endif + +#else + +/* No support: default to classic assertions */ +# define MPFR_DECL_STATIC_ASSERT(c) /* Nothing */ +# define MPFR_STAT_STATIC_ASSERT(c) MPFR_ASSERTN(c) + +#endif + +#endif |