Mercurial > hg > octave-nkf > gnulib-hg
annotate tests/test-stdbool.c @ 9938:9f8c455639fc
Fix rounding when a precision is given.
author | Bruno Haible <bruno@clisp.org> |
---|---|
date | Sat, 19 Apr 2008 17:26:36 +0200 |
parents | bbbbbf4cd1c5 |
children | b5e42ef33b49 |
rev | line source |
---|---|
8174 | 1 /* Test of <stdbool.h> substitute. |
2 Copyright (C) 2002-2007 Free Software Foundation, Inc. | |
3 | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8437
diff
changeset
|
4 This program is free software: you can redistribute it and/or modify |
8174 | 5 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8437
diff
changeset
|
6 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8437
diff
changeset
|
7 (at your option) any later version. |
8174 | 8 |
9 This program is distributed in the hope that it will be useful, | |
10 but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 GNU General Public License for more details. | |
13 | |
14 You should have received a copy of the GNU General Public License | |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
8437
diff
changeset
|
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8174 | 16 |
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */ | |
18 | |
19 #include <config.h> | |
20 | |
21 #include <stdbool.h> | |
22 | |
23 #ifndef bool | |
24 "error: bool is not defined" | |
25 #endif | |
26 #ifndef false | |
27 "error: false is not defined" | |
28 #endif | |
29 #if false | |
30 "error: false is not 0" | |
31 #endif | |
32 #ifndef true | |
33 "error: true is not defined" | |
34 #endif | |
35 #if true != 1 | |
36 "error: true is not 1" | |
37 #endif | |
38 #ifndef __bool_true_false_are_defined | |
39 "error: __bool_true_false_are_defined is not defined" | |
40 #endif | |
41 | |
8420 | 42 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */ |
8174 | 43 struct s { _Bool s: 1; _Bool t; } s; |
8420 | 44 #endif |
8174 | 45 |
46 char a[true == 1 ? 1 : -1]; | |
47 char b[false == 0 ? 1 : -1]; | |
48 char c[__bool_true_false_are_defined == 1 ? 1 : -1]; | |
8420 | 49 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */ |
8174 | 50 char d[(bool) 0.5 == true ? 1 : -1]; |
51 bool e = &s; | |
8420 | 52 #endif |
8174 | 53 char f[(_Bool) 0.0 == false ? 1 : -1]; |
54 char g[true]; | |
55 char h[sizeof (_Bool)]; | |
8437
166e8d07e046
Fix compilation error introduced in last commit.
Bruno Haible <bruno@clisp.org>
parents:
8420
diff
changeset
|
56 #if 0 /* See above. */ |
8174 | 57 char i[sizeof s.t]; |
8437
166e8d07e046
Fix compilation error introduced in last commit.
Bruno Haible <bruno@clisp.org>
parents:
8420
diff
changeset
|
58 #endif |
8174 | 59 enum { j = false, k = true, l = false * true, m = true * 256 }; |
60 _Bool n[m]; | |
61 char o[sizeof n == m * sizeof n[0] ? 1 : -1]; | |
62 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1]; | |
8420 | 63 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */ |
8174 | 64 #if defined __xlc__ || defined __GNUC__ |
65 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0 | |
66 reported by James Lemley on 2005-10-05; see | |
67 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html | |
68 This test is not quite right, since xlc is allowed to | |
69 reject this program, as the initializer for xlcbug is | |
70 not one of the forms that C requires support for. | |
71 However, doing the test right would require a run-time | |
72 test, and that would make cross-compilation harder. | |
73 Let us hope that IBM fixes the xlc bug, and also adds | |
74 support for this kind of constant expression. In the | |
75 meantime, this test will reject xlc, which is OK, since | |
76 our stdbool.h substitute should suffice. We also test | |
77 this with GCC, where it should work, to detect more | |
78 quickly whether someone messes up the test in the | |
79 future. */ | |
80 char digs[] = "0123456789"; | |
81 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1); | |
82 #endif | |
8420 | 83 #endif |
8174 | 84 /* Catch a bug in an HP-UX C compiler. See |
85 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html | |
86 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html | |
87 */ | |
88 _Bool q = true; | |
89 _Bool *pq = &q; | |
90 | |
91 int | |
92 main () | |
93 { | |
94 return 0; | |
95 } |