[Boost.Format] Erroneous Behaviour with %d Formatter
Hi all, I'm using Boost CVS version in the release branch. But according to the change log, it seems that this problem shall exist in Boost 1.33 too. I have the following code snippet, which doesn't produce the desired output: typedef unsigned char qquint8; qquint8 port = 1; boost::format fmt("Trying to probe COM%1$d:..."); std::cout << (fmt % port) << std::endl; The output will was: Trying to probe COM^A:... but what I want should be: Trying to probe COM1:... I understand that the underlying stream might have treated port as a character, thus output it as a character. But from Boost.Format's documentation, this doesn't seem obvious to me, since it always refers this as "printf-like" format string. So my question is: Is this considered a bug (thus, shall be fixed), or is it just considered a special case (thus, shall be explicitly documented under the "Differences of behaviour vs printf" section)? Cheers, Freddie -- Wu Yinghui, Freddie Research & Development Senior Software Engineer Volume Interactions Pte Ltd 1 Kim Seng Promenade, #12-01 Great World City East Tower Singapore 237994 Tel: +65 62226962 (Ext 216) Fax: +65 62226215 Email: yhwu@volumeinteractions.com URL: http://www.volumeinteractions.com Important: This message is intended for the recipient(s) addressed above. It contains privileged and confidential information. If you are not the intended recipient, please notify the sender immediately by replying to this message and then delete it from your system. You must not read, copy, use, or disseminate this communication in any form. Thank you.
Hi Freddie,
I reported this strange behaviour on the boost.devel list some time ago.
Unfortunately, I did not get an answer.
Several people I know ran into this trap and it would be very helpful if a
char is converted to int in case of %d formatter.
A cast to int should help:
std::cout << (fmt % (int)port) << std::endl;
Best regards,
Philipp
On 11/3/06, Wu Yinghui, Freddie
Hi all,
I'm using Boost CVS version in the release branch. But according to the change log, it seems that this problem shall exist in Boost 1.33 too.
I have the following code snippet, which doesn't produce the desired output:
typedef unsigned char qquint8; qquint8 port = 1; boost::format fmt("Trying to probe COM%1$d:..."); std::cout << (fmt % port) << std::endl;
The output will was: Trying to probe COM^A:... but what I want should be: Trying to probe COM1:...
I understand that the underlying stream might have treated port as a character, thus output it as a character. But from Boost.Format's documentation, this doesn't seem obvious to me, since it always refers this as "printf-like" format string.
So my question is: Is this considered a bug (thus, shall be fixed), or is it just considered a special case (thus, shall be explicitly documented under the "Differences of behaviour vs printf" section)?
Cheers,
Freddie
-- Wu Yinghui, Freddie Research & Development Senior Software Engineer
Volume Interactions Pte Ltd 1 Kim Seng Promenade, #12-01 Great World City East Tower Singapore 237994 Tel: +65 62226962 (Ext 216) Fax: +65 62226215 Email: yhwu@volumeinteractions.com URL: http://www.volumeinteractions.com
Important: This message is intended for the recipient(s) addressed above. It contains privileged and confidential information. If you are not the intended recipient, please notify the sender immediately by replying to this message and then delete it from your system. You must not read, copy, use, or disseminate this communication in any form. Thank you.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
participants (2)
-
Philipp Henkel
-
Wu Yinghui, Freddie