2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
36 #include "base/cprintf.hh"
47 cprintf("%shits%%s + %smisses%%s\n", "test", "test");
48 cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
49 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.141592653589, 1.1e10
);
51 cprintf("another test\n");
54 ccprintf(buffer
, "%-10s %c he home \'\"%d %#o %#x %1.5f %1.2E\n",
55 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.14159265, 1.1e10
);
57 double f
= 314159.26535897932384;
59 #define ctest(x, y) printf(x, y); cprintf(x, y); cprintf("\n");
67 ctest("%1000.8f\n", f
);
90 f
= 0.00000026535897932384;
108 ctest("%1.10f\n", f
);
109 ctest("%1.11f\n", f
);
110 ctest("%1.12f\n", f
);
111 ctest("%1.13f\n", f
);
112 ctest("%1.14f\n", f
);
113 ctest("%1.15f\n", f
);
114 ctest("%1.16f\n", f
);
115 ctest("%1.17f\n", f
);
116 ctest("%1.18f\n", f
);
118 f
= 0.00000026535897932384;
125 ctest("%12.8e\n", f
);
136 ctest("%1.10e\n", f
);
137 ctest("%1.11e\n", f
);
138 ctest("%1.12e\n", f
);
139 ctest("%1.13e\n", f
);
140 ctest("%1.14e\n", f
);
141 ctest("%1.15e\n", f
);
142 ctest("%1.16e\n", f
);
143 ctest("%1.17e\n", f
);
144 ctest("%1.18e\n", f
);
146 cout
<< buffer
.str();
152 string foo1
= "string test";
153 cprintf("%s\n", foo1
);
156 foo2
<< "stringstream test";
157 cprintf("%s\n", foo2
);
159 cprintf("%c %c\n", 'c', 65);