test-stdbool.c

Go to the documentation of this file.
00001 /* Test of <stdbool.h> substitute.
00002    Copyright (C) 2002-2007 Free Software Foundation, Inc.
00003 
00004    This program is free software: you can redistribute it and/or modify
00005    it under the terms of the GNU General Public License as published by
00006    the Free Software Foundation; either version 3 of the License, or
00007    (at your option) any later version.
00008 
00009    This program is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012    GNU General Public License for more details.
00013 
00014    You should have received a copy of the GNU General Public License
00015    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00016 
00017 /* Written by Bruno Haible <bruno@clisp.org>, 2007.  */
00018 
00019 #include <config.h>
00020 
00021 #include <stdbool.h>
00022 
00023 #ifndef bool
00024  "error: bool is not defined"
00025 #endif
00026 #ifndef false
00027  "error: false is not defined"
00028 #endif
00029 #if false
00030  "error: false is not 0"
00031 #endif
00032 #ifndef true
00033  "error: true is not defined"
00034 #endif
00035 #if true != 1
00036  "error: true is not 1"
00037 #endif
00038 #ifndef __bool_true_false_are_defined
00039  "error: __bool_true_false_are_defined is not defined"
00040 #endif
00041 
00042 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
00043 struct s { _Bool s: 1; _Bool t; } s;
00044 #endif
00045 
00046 char a[true == 1 ? 1 : -1];
00047 char b[false == 0 ? 1 : -1];
00048 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
00049 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
00050 char d[(bool) 0.5 == true ? 1 : -1];
00051 bool e = &s;
00052 #endif
00053 char f[(_Bool) 0.0 == false ? 1 : -1];
00054 char g[true];
00055 char h[sizeof (_Bool)];
00056 #if 0 /* See above.  */
00057 char i[sizeof s.t];
00058 #endif
00059 enum { j = false, k = true, l = false * true, m = true * 256 };
00060 _Bool n[m];
00061 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
00062 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
00063 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>.  */
00064 #if defined __xlc__ || defined __GNUC__
00065  /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
00066     reported by James Lemley on 2005-10-05; see
00067     http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
00068     This test is not quite right, since xlc is allowed to
00069     reject this program, as the initializer for xlcbug is
00070     not one of the forms that C requires support for.
00071     However, doing the test right would require a run-time
00072     test, and that would make cross-compilation harder.
00073     Let us hope that IBM fixes the xlc bug, and also adds
00074     support for this kind of constant expression.  In the
00075     meantime, this test will reject xlc, which is OK, since
00076     our stdbool.h substitute should suffice.  We also test
00077     this with GCC, where it should work, to detect more
00078     quickly whether someone messes up the test in the
00079     future.  */
00080  char digs[] = "0123456789";
00081  int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
00082 #endif
00083 #endif
00084 /* Catch a bug in an HP-UX C compiler.  See
00085    http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
00086    http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
00087  */
00088 _Bool q = true;
00089 _Bool *pq = &q;
00090 
00091 int
00092 main ()
00093 {
00094   return 0;
00095 }

Generated on Tue Oct 21 18:28:19 2008 for gsasl by  doxygen 1.5.6