
Hi, I'm testing Boost with Comeau C/C++ frontent which, as far as I found, does not support mixing C++ and C99 modes. So, compiling Boost.Test library fails because ::snprintf can not be found [1]. I could not find any guidelines regarding use of elements of C99 in Boost libraries (are there any?). Scanning Boost libraries for snprintf shows that it's not widely used, but only in 3 files: boost/test/impl/debug.ipp boost/test/impl/execution_monitor.ipp libs/format/benchmark/bench_format.cpp Would it make sense to remove use of snprintf? [1] https://svn.boost.org/trac/boost/ticket/3558 Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org

Mateusz Loskot <mateusz <at> loskot.net> writes:
Hi,
I'm testing Boost with Comeau C/C++ frontent which, as far as I found, does not support mixing C++ and C99 modes. So, compiling Boost.Test library fails because ::snprintf can not be found [1].
Would it make sense to remove use of snprintf?
I'd like to continue using snprintf. Can please provide any kind of workaround? Gennadiy

As I known, the C standard function snprintf renamed to _snprintf in MSVC, maybe that caused your problem. 2009/11/23 Gennadiy Rozental <rogeeff@gmail.com>
Mateusz Loskot <mateusz <at> loskot.net> writes:
Hi,
I'm testing Boost with Comeau C/C++ frontent which, as far as I found, does not support mixing C++ and C99 modes. So, compiling Boost.Test library fails because ::snprintf can not be found [1].
Would it make sense to remove use of snprintf?
I'd like to continue using snprintf. Can please provide any kind of workaround?
Gennadiy
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Bo Schwarzstein wrote:
As I known, the C standard function snprintf renamed to _snprintf in MSVC, maybe that caused your problem.
snprintf is C99 function. Visaul C++ defines similar function _snprintf, however it is not equivalent 100% compatible with snprintf defined in C99. Nevertheless, Comeau does not define snprintf in C++ mode. So, in order to compile Boost.Test using Comeau, it needs to be emulated, possibly using <sstream> features. Gennadiy, would it be acceptable? Best regards, -- Mateusz Loskot, http://mateusz.loskot.net

It is probably easier to emulate snprintf using Boost.Format. I'm not sure what requirements you have that cause you to want to continue using snprintf, but you may find that you can simply switch from snprintf to Boost.Format (with no emulation). On Nov 23, 2009, at 9:04 AM, Mateusz Loskot wrote:
Bo Schwarzstein wrote:
As I known, the C standard function snprintf renamed to _snprintf in MSVC, maybe that caused your problem.
snprintf is C99 function. Visaul C++ defines similar function _snprintf, however it is not equivalent 100% compatible with snprintf defined in C99.
Nevertheless, Comeau does not define snprintf in C++ mode. So, in order to compile Boost.Test using Comeau, it needs to be emulated, possibly using <sstream> features.
Gennadiy, would it be acceptable?
Best regards, -- Mateusz Loskot, http://mateusz.loskot.net _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Ian Emmons wrote:
It is probably easier to emulate snprintf using Boost.Format. I'm not sure what requirements you have that cause you to want to continue using snprintf, but you may find that you can simply switch from snprintf to Boost.Format (with no emulation).
I believe there is confusion. As far as I'm concerned, I do not have any such requirements. It is that I was told (see comments here [1]) that Boost.Test will continue using snprintf, so I'm looking for workaround that would be acceptable for Boost.Test. Boost.Format works for me. Does it work for Boost.Test? [1] https://svn.boost.org/trac/boost/ticket/3558 Best regards, -- Mateusz Loskot, http://mateusz.loskot.net

I'm sorry, I meant to direct my suggestion to Gennadiy, but I lost track of whose message I had replied to. On Nov 23, 2009, at 10:38 AM, Mateusz Loskot wrote:
Ian Emmons wrote:
It is probably easier to emulate snprintf using Boost.Format. I'm not sure what requirements you have that cause you to want to continue using snprintf, but you may find that you can simply switch from snprintf to Boost.Format (with no emulation).
I believe there is confusion. As far as I'm concerned, I do not have any such requirements. It is that I was told (see comments here [1]) that Boost.Test will continue using snprintf, so I'm looking for workaround that would be acceptable for Boost.Test.
Boost.Format works for me. Does it work for Boost.Test?
[1] https://svn.boost.org/trac/boost/ticket/3558
Best regards, -- Mateusz Loskot, http://mateusz.loskot.net _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost

Mateusz Loskot <mateusz <at> loskot.net> writes:
Boost.Format works for me. Does it work for Boost.Test?
No. This is really low level function, which is using snprintf: 1. I do not want any extra dependencies 2. There is a requirement of no memory allocations 3. I do not need any fancy formatting. I just want to validate that there is not preallocated buffer overrun. Gennadiy

Gennadiy Rozental a écrit, le 23/11/2009 17:37:
No. This is really low level function, which is using snprintf:
As I am currently updating boost.format (to answer feature requests, and also improve performance : iostreams used to be so much slower than printf that optimizing boost.format didn't make much sense - now it seems g++ streams/locale were significantly improved so I got back to it, and aims for 10%-20% overhead compared to equivalent stream operations) Anyway, it's interesting to hear about various formatting usages. There is probably a few incompatible constraints between those that require low-level low-flexibility and those who need more flexibility (at a cost), with C++0x on the horizon it could be a good time to rethink how boost want to handle formatting (and the different kinds of formattings).
2. There is a requirement of no memory allocations
Why ? Is it no memory allocations per-se, or rather no memory allocations each and every call (because of performance impact) ? If it is the latter, reusing a static format object (or stringstream, or a modified version that could write to a static buffer - like the custom stringstream written for boost.format) can solve the issue in single thread. And "thread_local static" makes it work in multi-thread too, but of course that keyword can not be relied on yet. If you really can not allow any memory allocation then you're on your own if you can not use snprintf either.
3. I do not need any fancy formatting. I just want to validate that there is not preallocated buffer overrun.
Really basic formatting, like just dumping integers into a char buffer can be portably coded in a few lines if snprintf is not available. Or you could maybe implement an output iterator that writes into the char buffer (and checks for end of buffer) and use it with the num_put facet. So, if snprintf really can not be made available on (almost) all platforms, it might make sense to implement some basic number-to-char-buffer facility in boost, that does not rely on snprintf (nor locales, maybe). But that kind of basic function would not directly replace snprintf for some of Boost.Test lines : (in debug.ipp:320) ::snprintf( title_str, sizeof(title_str), "%*s %ld", (int)(dsi.binary_path.end()-it), it, dsi.pid ); Couldn't Comeau just make snprintf available to its C++ compiler ? And is there any other platform that lacks snprintf ? -- Samuel

Mateusz Loskot <mateusz <at> loskot.net> writes:
Bo Schwarzstein wrote:
As I known, the C standard function snprintf renamed to _snprintf in MSVC, maybe that caused your problem.
snprintf is C99 function. Visaul C++ defines similar function _snprintf, however it is not equivalent 100% compatible with snprintf defined in C99.
Seems to be working fine for our purposes.
Nevertheless, Comeau does not define snprintf in C++ mode.
So, in order to compile Boost.Test using Comeau, it needs to be emulated, possibly using <sstream> features.
Gennadiy, would it be acceptable?
I'd rather use wrapper around sprintf, which drops n. Gennadiy

Gennadiy Rozental wrote:
Mateusz Loskot <mateusz <at> loskot.net> writes:
Hi,
I'm testing Boost with Comeau C/C++ frontent which, as far as I found, does not support mixing C++ and C99 modes. So, compiling Boost.Test library fails because ::snprintf can not be found [1].
Would it make sense to remove use of snprintf?
I'd like to continue using snprintf. Can please provide any kind of workaround?
Gennadiy, I've prepared a simple workaround for missing snprintf and vsnprintf functions. Patch attached to the ticket [1] Due to the fact that these functions are used not only in Boost.Test, I thought it may be a good idea Boost.Config gives some hints about their availability, so I also updated boost/config/platform/linux.hpp with two definitions for Linux && Comeau # define BOOST_NO_SNPRINTF # define BOOST_NO_VSNPRINTF I have very little knowledge about internals of Boost.Config, so I'm not sure if that is proper approach. By the way, I also submitted new ticket [2] with small patch that enables POSIX/SVID support for Comeau toolset. To summary, these two patches fix the related problems, however I found some further issues which I'm investigating, and hopefully, patching. [1] https://svn.boost.org/trac/boost/ticket/3558 [2] https://svn.boost.org/trac/boost/ticket/3662 Best regards, -- Mateusz Loskot, http://mateusz.loskot.net Charter Member of OSGeo, http://osgeo.org
participants (5)
-
Bo Schwarzstein
-
Gennadiy Rozental
-
Ian Emmons
-
Mateusz Loskot
-
Samuel Krempp