Standard C Library and C++ / BOOST

Dear BOOST folks, Here's an recipe idea for a BOOST library: Take the Standard C Library. Create a new namespace, "boost::xtd::" for instance. For every function in the Standard C Library, create an analog in the "boost::xtd::" namespace. The analog function would have the same functional behavior as the StdCLib function, with the notable difference that any errors will generate an exception. Some of my projects here at work have done something similar, with a limited subset of C. That subset being only those handful of routine that we cared about. The value of having this in the BOOST repertoire: 1. a (BOOST) standard convention that would be the same for everyone 2. maybe it'd get folded into ISO/IEC 14882 at some future point 3. Standard C Library with C++ exceptions Example 18 header files being... <boost/xtd/stdio.hpp> <boost/xtd/stdlib.hpp> <boost/xtd/stddef.hpp> <boost/xtd/stdassert.hpp> <boost/xtd/time.hpp> <boost/xtd/errno.hpp> <boost/xtd/ctype.hpp> <boost/xtd/wtype.hpp> <boost/xtd/string.hpp> <boost/xtd/wchar.hpp> <boost/xtd/locale.hpp> <boost/xtd/limits.hpp> <boost/xtd/float.hpp> <boost/xtd/setjmp.hpp> <boost/xtd/signal.hpp> <boost/xtd/math.hpp> <boost/xtd/iso646.hpp> <boost/xtd/stdarg.hpp> Opinions of this idea merits being implemented? Does it sound appropriate for a BOOST library? Sincerely, John "Eljay" Love-Jensen Adobe Systems Incorporated

Eljay Love-Jensen wrote:
Take the Standard C Library. Create a new namespace, "boost::xtd::" for instance. For every function in the Standard C Library, create an analog in the "boost::xtd::" namespace. The analog function would have the same functional behavior as the StdCLib function, with the notable difference that any errors will generate an exception.
Personally, I find this to be a good idea. Whenever I had to write code like: int controlling_tty = open(ctermid(0), O_RDWR); if (controlling_tty == -1) perror("open"); int result = tcsetpgrp(controlling_tty, parent_group); if (result == -1) perror("tcsetpgrp"); I really wish there were exception-throwing versions -- since that code is boring and still contains a couple of error-handling problems. However, most of the functions above are acutally from POSIX, not from standard C, so I'm not sure how much wrapped C functions would help me. - Volodya

From: Eljay Love-Jensen <eljay@adobe.com>
Take the Standard C Library.
Yes! Take it, please! ;-)
Create a new namespace, "boost::xtd::" for instance. For every function in the Standard C Library, create an analog in the "boost::xtd::" namespace. The analog function would have the same functional behavior as the StdCLib function, with the notable difference that any errors will generate an exception. [snip] Opinions of this idea merits being implemented?
The first question to ask is whether an exception is the right way to handle an error for each case. Often it isn't. The next question to ask is whether there is already a better alternative available in C++. For example, instead of strtok() et al, you should use Boost.Tokenizer. Finally, if there isn't a better alternative, and the functionality is needed, you must ask whether there aren't aspects of the C function that couldn't be made better in C++. In that case, you'd create the new function or class to work in a C++ way. Thus, I don't see much merit in wrapping all of the C Library functions so they throw exceptions. -- Rob Stewart stewart@sig.com Software Engineer http://www.sig.com Susquehanna International Group, LLP using std::disclaimer;
participants (3)
-
Eljay Love-Jensen
-
Rob Stewart
-
Vladimir Prus