Does libcxxabi makes sense under linux? What are the benefits?

You should not use libcxxabi directly. To my understanding it is a kind of platform abstraction library, providing low level functions needed to implement libcxx. If you are asking about using libcxx or libstdc++, the differences are mostly the license, newer standard version completeness (the clang project seems slightly faster in implementing recent C++ revisions) …

Read more

Should I free/delete char* returned by getenv()?

No you shouldn’t. Standard 7.20.4.5 says : The getenv function returns a pointer to a string associated with the matched list member. The string pointed to shall not be modified by the program, but may be overwritten by a subsequent call to the getenv function. I believe deletion is covered by the text in bold.

Why is initializing a string to “” more efficient than the default constructor?

This is an intentional decision in libc++’s implementation of std::string. First of all, std::string has so-called Small String Optimization (SSO), which means that for very short (or empty) strings, it will store their contents directly inside of the container, rather than allocating dynamic memory. That’s why we don’t see any allocations in either case. In …

Read more

Is make_shared really more efficient than new?

As infrastructure I was using llvm/clang 3.0 along with the llvm std c++ library within XCode4. Well that appears to be your problem. The C++11 standard states the following requirements for make_shared<T> (and allocate_shared<T>), in section 20.7.2.2.6: Requires: The expression ::new (pv) T(std::forward(args)…), where pv has type void* and points to storage suitable to hold …

Read more

What does the first “c” stand for in “calloc”?

According to an excerpt from the book Linux System Programming (by Robert Love), no official sources exist on the etymology of calloc. Some plausible candidates seem to be: Count or counted, because calloc takes a separate count argument. Clear, because it ensures that the returned memory chunk has been cleared. Brian Kernighan is reported to …

Read more

Why can’t clang with libc++ in c++0x mode link this boost::program_options example?

You need to rebuild boost using clang++ -stdlib=libc++. libc++ is not binary compatible with gcc’s libstdc++ (except for some low level stuff such as operator new). For example the std::string in gcc’s libstdc++ is refcounted, whereas in libc++ it uses the “short string optimization”. If you were to accidentally mix these two strings in the …

Read more

How to compile/link Boost with clang++/libc++?

I didn’t know how to do this either. But after poking around in here, the getting started, and trial and error: $ ./bootstrap –with-toolset=clang $ ./b2 clean $ ./b2 toolset=clang cxxflags=”-stdlib=libc++” linkflags=”-stdlib=libc++” You’ll get lots of warnings. And the signals library will fail to build due to LWG 2059. But otherwise I think it works.