0

For our current project, we are thinking to use Boost framework.

However, the project should be truly cross-platform and might be shipped to some exotic platforms. Therefore, we would like to use only Boost packages (libraries) that does not contain any platform specific code: pure C++ and that's all.

Boost has the idea of header-only packages (libraries).

Can one assume that these packages (libraries) are free from platform specific code? In case if not, is there a way to identify these kind of packages of Boost?

Auryin
  • 3
  • 2
  • Some parts of Boost (even headers) rely on specific compilers. Check that your compiler is supported. – Claudio Sep 30 '14 at 15:57
  • 7
    Boost is cross platform by design? I don't get what you're actually asking for? Either you can build the libraries for a specific platform and toolchain, or you cannot. – πάντα ῥεῖ Sep 30 '14 at 15:57
  • Yes, it's cross-platform by design. However, I guess there is a difference between "thread" and "smart_ptr" packages of boost. One should depend on platform specific code (at least in C++98) and the other one could be pure C++ implementation. We are trying to find those packages of Boost which does not contain platform specific code. – Auryin Sep 30 '14 at 16:04
  • 2
    The point of the library is to abstract away the "platform specific" and "pure C++" parts into common interface. If it supports the platform you plan to ship on, why do you care exactly what it uses under the hood? Yes, it will use `pthread_create` on linux and `CreateThread` on windows, but you'll only have to use `boost::thread`. – jrok Sep 30 '14 at 16:07
  • Where boost is platform specific, it is mainly to insulate platform and non conformant compiler issues from the library user. Only using pure c++ would result in much less portable code. – Maarten Hilferink Sep 30 '14 at 16:07
  • @jrok The future list of platforms are unclear to us. Hence, we don't know in these stage, will Boost support platform or not. However, we would like to gain from Boost packages that are free from platform specific code. – Auryin Sep 30 '14 at 16:13
  • I bet if you skim through the documentation of each of the lib you're interested in you'll find a section saying which platform (if any) it has trouble with. – jrok Sep 30 '14 at 16:26
  • @πάνταῥεῖ at least Boost Context has limited platform implementations. Hence every library that depends on it (Boost Coroutine, Boost Asio?) will have impact if it's not available. And, e.g. Boost Asio has POSIX and Win32 non-portable extensions. – sehe Sep 30 '14 at 16:46
  • @Auryin "the other one ["smart_ptr"] could be pure C++ implementation." The smart pointer library most definitely is not just standard C++, because `shared_ptr` has thread-safety guarantees that require atomic operations on the reference-count, which is implemented with a platform-specific functions or compiler-specific built-in functions. But a platform / compiler that supports TR1 must also have that support, so it should work. I say, limit your use of boost libraries, and test it on your "exotic" platforms. – Mikael Persson Sep 30 '14 at 17:27
  • @Auryin Also, your question is a bit unclear about what you mean by platform specific code. Boost.Config is where most of the platform identification goes on, and it distinguishes mainly the compiler vendor and version, the standard library vendor and version, and the OS API (e.g., Win32, POSIX, Mac OSX or QNX (both close nearly POSIX), etc..). If you take a look at all the switches and stuff in Boost.Config, you will soon realize that there is no clear dividing line between "only pure C++" and "platform-specific code"... because "pure C++" is an ideal, not a reality. – Mikael Persson Sep 30 '14 at 17:35
  • @MikaelPersson Choice for "smart_ptr" was for example, however, I admit it was not a good choice for "pure C++" implemented library (boost::any will be better choice :)). – Auryin Sep 30 '14 at 17:52
  • @MikaelPersson The compiler version and vendor is not an issue, as our code is based on C++11 and we assume that the future platforms are going to support it at least. More importantly is the platform specific part of libraries. I believe, all of us agree that there are some libraries in boost (like boost::any, boost::property_tree) which does not contain platform specific code. The question was is there some way to pull all that libraries. As far as I understand there is no, except going library by library manually and check the documentation and pull them (no bootstrap/b2 usage for example). – Auryin Sep 30 '14 at 17:55
  • @Auryin You could set up an environment that is representative of your most "exotic" / deprived environment, whatever that may be in the real world (as it's not clear at all from your question). Then, create regression tests for the boost libraries that you use in your project, such that you can verify, per boost version and library, which compiles successfully on that "worst-case" platform. If you cannot come up with such a worst-case platform(s), then it's an indication that what is or isn't an acceptable level of platform-specific code is ill-defined and you have to think more about it. – Mikael Persson Sep 30 '14 at 18:07

2 Answers2

1

All C++ code is platform-specific to some extent. On the one side, there is this ideal concept of "pure standard C++ code", and on the other side, there is reality. Most of the Boost libraries are designed to maintain the ideal situation on the user-side, meaning that you, as the user of Boost, can write platform-agnostic standard C++ code, while all the underlying platform-specific code is hidden away in the guts of those Boost libraries (for those that need them).

But at the core of this issue is the problem of how to define platform-specific code versus standard C++ code in the real world. You can, of course, look at the standard document and say that anything outside of it is platform-specific, but that's nothing more than an academic discussion.

If we start from this scenario: assume we have a platform that only has a C++ compiler and a C++ standard library implementation, and no other OS or OS-specific API to rely on for other things that aren't covered by the standard library. Well, at that point, you still have to ask yourself:

  • What compiler is this? What version?
  • Is the standard library implementation correct? Bug-free?
  • Are those two entirely standard-compliant?

As far as I know, there is essentially no universal answer to this and there are no realistic guarantees. Most exotic platforms rely on exotic (or old) compilers with partial or non-compliant standard library implementations, and sometimes have self-imposed restrictions (e.g., no exceptions, no RTTI, etc.). An enormous amount of "pure standard C++ code" would never compile on these platforms.

Then, there is also the reality that most platforms today, even really small embedded systems have an operating system. The vast majority of them are POSIX compliant to some level (except for Windows, but Windows doesn't support any exotic platform anyways). So, in effect, platform-specific code that relies on POSIX functions is not really that bad since it is likely that most exotic platforms have them, for the most part.

I guess what I'm really getting at here is that this pure dividing line that you have in your mind about "pure C++" versus platform-specific code is really just an imaginary one. Every platform (compiler + std-lib + OS + ext-libs) lies somewhere along a continuum of level of support for standard language features, standard library features, OS API functions, and so on. And by that measure, all C++ code is platform-specific.

The only real question is how wide of a net it casts. For example, most Boost libraries (except for recent "flimsy" ones) generally support compilers down to a reasonable level of C++98 support, and many even try to support as far back as early 90s compilers and std-libs.

To know if a library, part of Boost or not, has wide enough support for your intended applications or platforms, you have the define the boundaries of that support. Just saying "pure C++" is not enough, it means nothing in the real world. You cannot say that you will be using C++11 compilers just after you've taken Boost.Thread as an example of a library with platform-specific code. Many C++11 implementations have very flimsy support for std::thread, but others do better, and that issue is as much of a "platform-specific" issue as using Boost.Thread will ever be.

The only real way to ever be sure about your platform support envelope is to actual set up machines (e.g., virtual machines, emulators, or real hardware) that will provide representative worst-cases. You have to select those worst-case machines based on a realistic assessment of what your clients may be using, and you have to keep that assessment up to date. You can create a regression test suite for your particular project, that uses the particular (Boost) libraries, and test that suite on all your worst-case test environments. Whatever doesn't pass the test, doesn't pass the test, it's that simple. And yes, you might find out in the future that some Boost library won't work under some new exotic platform, and if that happens you need to either get the Boost dev-team to add code to support it, or you have to re-write your code to get around it, but that's what software maintenance is all about, and it's a cost you have to anticipate, and such problems will come not only from Boost, but from the OS and from the compiler vendors too! At least, with Boost, you can fix the code yourself and contribute it to Boost, which you can't always do with OS or compiler vendors.

Mikael Persson
  • 18,174
  • 6
  • 36
  • 52
1

We had "Boost or not" discussion too. We decided not to use it.

  • We had some untypical hardware platforms to serve with one source code. Especially running boost on AVR was simply impossible because RTTI and exceptions, which Boost requires for a lot of things, aren't available.
  • There are parts of boost which use compiler specific "hacks" to e.g. get information about class structure.
  • We tried splitting the packages, but the inter dependency is quite high (at least 3 or 4 years ago).

In the meantime, C++11 was underway and GCC started supporting more and more. With that many reasons to use from boost faded (Which Boost features overlap with C++11?). We implemented the rest of our needs from scratch (with relative low effort thanks to variadic templates and other TMP features in C++11).

After a steep learning curve we have all we need without external libraries.

At the same time we have pondered the future of Boost. We expected the newly standardized C++11 features would be removed from boost. I don't know the current roadmap for Boost, but at the time our uncertainty made us vote against Boost.


This is not a real answer to your question, but it may help you decide whether to use Boost. (And sorry, it was to large for a comment)

Community
  • 1
  • 1
Klaus
  • 24,205
  • 7
  • 58
  • 113
  • This seems quite biased and possibly outdated. We have [better posts about this](http://stackoverflow.com/questions/1226206/is-there-a-reason-to-not-use-boost). Where are the _'"hacks" to e.g. get information about class structure'_? Splitting the packages is [easy with BCP](http://stackoverflow.com/a/13423990/85371). The inter dependencies are true (mpl, typetraits, utility, core are basically indispensible). I'm not saying you made the wrong choice. – sehe Sep 30 '14 at 23:27