Boost C++ Libraries: Ticket #2024: boost::format("%p") % (uint8_t *) str is not like printf("%p", str) https://svn.boost.org/trac10/ticket/2024 <p> I'm actually on 1.33.1 still but I can't see any difference that fixes this in the latest code. </p> <p> The boost::format gets pointers to 8-bit types wrong. This because the underlying type is indistinguishable from a string. In this case, I think the formatting needs to take the hint from the format string about how to interpret the type. </p> <p> I have a fix which is slightly hacky. Instead of passing the printf parameter directly to %, it can be wrapped in a container whose insertion method inspects the stream flags to see whether any of the basefield bits are set and only prints like a char/string if none of them are. The wrapper type is in the attachment. The format parsing needs to clear the basefield bits. Here is the diff from format/parsing.hpp: </p> <p> 321d320 &lt; fpar-&gt;fmtstate_.flags_ &amp;= ~std::ios_base::basefield; 326d324 &lt; fpar-&gt;fmtstate_.flags_ &amp;= ~std::ios_base::basefield; </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2024 Trac 1.4.3 Geoff Barrett <gbarrett@…> Thu, 19 Jun 2008 15:25:20 GMT attachment set https://svn.boost.org/trac10/ticket/2024 https://svn.boost.org/trac10/ticket/2024 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">format_printf.cc</span> </li> </ul> Ticket Marshall Clow Sun, 28 Mar 2010 02:47:35 GMT <link>https://svn.boost.org/trac10/ticket/2024#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/2024#comment:1</guid> <description> <p> This still a problem in 1.42: </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/format.hpp&gt; #include &lt;cstdlib&gt; int main ( int argc, char *argv[] ) { const char *foo = "Hi Mom!"; std::cout &lt;&lt; str ( boost::format ( "%p" ) % foo ) &lt;&lt; std::endl; printf ( "%p\n", foo ); return 0; } </pre><p> prints two different lines. </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Marshall Clow</dc:creator> <pubDate>Mon, 14 Jun 2010 01:05:17 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/2024#comment:2 https://svn.boost.org/trac10/ticket/2024#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">wontfix</span> </li> </ul> <p> My copy of the C99 standard (n869) says about "%p": </p> <p> p The argument shall be a pointer to void. The value of the pointer is converted to a sequence of printing characters, in an implementation-defined manner. </p> <p> Given that, I don't see any way that Boost.Format can "match what printf prints". </p> Ticket