• Boost: Shared pointers

    The Boost Smart Pointers library provides a set of classes to manage pointers. I've started using boost::shared_ptr and am very happy with the results. Let's see what it is. shared_ptr is a simple templated class that holds a pointer to a dynamically allocated object, which is reference counted. The object it references is automatically destroyed when the last instance of the smart pointer is removed; this usually happens when it gets out of its code scope.

  • Boost: First impressions

    Despite my previous post, I decided to give a try to Boost and switched VCS Made Easy to use some of its libraries; the modified source code is not yet on the public server (hmm, the joys of Monotone), but I think it'll be soon. I must say that the results are very satisfactory. At first, I dropped my custom file and directory classes in favor of Boost.Filesystem. During the conversion, I had to rework some of the existing code to comply with Boost's guidelines WRT global (environment) variables and portability.

  • Boost: To use or not to use it

    For at least two weeks, I've been rewriting VCS Made Easy from scratch (and it's already working fairly well), a project I announced a long time ago. It's being written in C++ and the code is organized in three (independent) layers: The helper library: This provides classes to access operating system specific details. Among others, it has classes to manage processes, users, files, directories, etc. Everything is very simple and, depending on how you look at it, incomplete.

  • Passing information to configure scripts

    GNU Autoconf provides three ways to pass information to the generated configure scripts; these are enable-style flags, with-style flags and command line variables. Despite each one is provided with a very concrete goal in mind, many people overloads their meaning. Their purpose is clearly described in the manual, which these people "forget" to read. (I know it's impossible to read everything one would like to... not an excuse in this case, I'd say.

  • How to get the user's home directory

    Many programs need to access the user's home directory to look for files, specially configuration ones. To do that, they usually get the HOME environment variable's value and use it to construct the full path. However, if the application is security-sensible, this is probably inappropriate. What happens if such application is run through sudo or with the setuid bit set? Let's see it: [dawn jmmv] $ sudo /bin/sh -c 'id -un ; echo ${HOME}'

  • C++: Verifying program sanity

    The C language provides a macro, called assert, that is used to verify conditions that must be true at any point of the program. These include preconditions, postconditions and invariants, all of which are explained in introductory programming courses. Whenever an assertion is violated, the program is abruptly stopped because there is most likely a bug in its code. C++, like C, also provides the assert macro in the cassert standard header.

  • C++: Containers of pointers

    One of the things C++ provides to programmers is that pointers can be avoided in much situations, and IMHO, they should be (specially in public class interfaces). However, there are some times in which pointers must be used. Consider an abstract base class and multiple specializations of it; if you want to define a container of all these objects, no matter which derived class they belong to, the container must hold the parent's type.