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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of <stdbool.h> substitute.
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2002-2007 Free Software Foundation, Inc.
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <stdbool.h>
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #ifndef bool
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 "error: bool is not defined"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #ifndef false
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 "error: false is not defined"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #if false
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 "error: false is not 0"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #ifndef true
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 "error: true is not defined"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #if true != 1
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 "error: true is not 1"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #ifndef __bool_true_false_are_defined
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 "error: __bool_true_false_are_defined is not defined"
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #endif
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
42 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 struct s { _Bool s: 1; _Bool t; } s;
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
44 #endif
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 char a[true == 1 ? 1 : -1];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 char b[false == 0 ? 1 : -1];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 char c[__bool_true_false_are_defined == 1 ? 1 : -1];
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
49 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 char d[(bool) 0.5 == true ? 1 : -1];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 bool e = &s;
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
52 #endif
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 char f[(_Bool) 0.0 == false ? 1 : -1];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 char g[true];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
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
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 enum { j = false, k = true, l = false * true, m = true * 256 };
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 _Bool n[m];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 char o[sizeof n == m * sizeof n[0] ? 1 : -1];
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 char p[-1 - (_Bool) 0 < 0 && -1 - (bool) 0 < 0 ? 1 : -1];
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
63 #if 0 /* Cannot be guaranteed with gnulib's <stdbool.h>. */
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 #if defined __xlc__ || defined __GNUC__
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Catch a bug in IBM AIX xlc compiler version 6.0.0.0
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 reported by James Lemley on 2005-10-05; see
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 http://lists.gnu.org/archive/html/bug-coreutils/2005-10/msg00086.html
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 This test is not quite right, since xlc is allowed to
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 reject this program, as the initializer for xlcbug is
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 not one of the forms that C requires support for.
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 However, doing the test right would require a run-time
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 test, and that would make cross-compilation harder.
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 Let us hope that IBM fixes the xlc bug, and also adds
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 support for this kind of constant expression. In the
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 meantime, this test will reject xlc, which is OK, since
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 our stdbool.h substitute should suffice. We also test
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 this with GCC, where it should work, to detect more
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 quickly whether someone messes up the test in the
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 future. */
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 char digs[] = "0123456789";
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 int xlcbug = 1 / (&(digs + 5)[-2 + (bool) 1] == &digs[4] ? 1 : -1);
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 #endif
8420
baddd6f5c9a3 Avoid test failures.
Bruno Haible <bruno@clisp.org>
parents: 8174
diff changeset
83 #endif
8174
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 /* Catch a bug in an HP-UX C compiler. See
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 http://gcc.gnu.org/ml/gcc-patches/2003-12/msg02303.html
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 http://lists.gnu.org/archive/html/bug-coreutils/2005-11/msg00161.html
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 */
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 _Bool q = true;
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 _Bool *pq = &q;
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 int
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 main ()
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 {
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 return 0;
cf901d1dce6a Tests for module 'stdbool'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 }