Header files: Series wrap-up

Happy New Year! Let me welcome 2014 with a very simple post to wrap up the header files series as is customary so that you have all relevant links in a single place for future reference: Series introduction Multiple-inclusion protection Self-containment C++ ipp files Avoid C++ “using” directives Poor man’s replacement for modules Qualify your identifiers Poor compilation times in C++ As I mentioned a couple of posts ago, I am quite busy these days spending my limited free time on Kyua-related hacking, which means you should expect a less constant blogging pace.

January 1, 2014 · Tags: header-files
Continue reading (about 1 minute)

Header files: Poor compilation times in C++

Have you ever wondered why building C++ code is so awfully slow and, apparently, compilation times haven’t gotten any better over the course of many years? Wonder no more. This article on C++ Compilation Speed published on August 17, 2010 on Dr. Dobb’s delves into the problem. Mind you, a major cause of such slowdowns are header files and the fact that they are a horrible replacement for a modules system.

December 30, 2013 · Tags: header-files
Continue reading (about 1 minute)

Header files: Qualify your identifiers

Apologies for the long pause in the header files series and in blogging in general. With the holidays in between and, especially, with my refreshed energy to do stuff in the FreeBSD and Kyua camps, I haven’t had any reasonable amount of time to write. And, sincerely, with my very limited free time I really cannot cover it all. So… these days, coding it is thus expect a reduced blogging pace!

December 27, 2013 · Tags: header-files
Continue reading (about 2 minutes)

Header files: Poor man's replacement for modules

I don’t like header files and, especially, I don’t like having to use them to implement modules. When you have used a language that sports real modules—pretty much anything other than C or sh—, header files feel primitive. Well, they actually are primitive. But what do I mean by “real modules”? Modules! In a language that supports modules, a module is a collection of related data types and code exposed via a well-defined set of symbols encapsulated in a single container (name).

December 9, 2013 · Tags: header-files
Continue reading (about 4 minutes)

Header files: Avoid C++ 'using' directives

Following up on the previous C++ post, here comes one more thing to consider when writing header files in this language. using and using namespace The C++ using directive and its more generic using namespace counterpart, allow the programmer to bring a given symbol or all the symbols in a namespace, respectively, into the calling scope. This feature exists to simplify typing and, to some extent, to make the code more readable.

December 5, 2013 · Tags: cxx, header-files
Continue reading (about 3 minutes)

Header files: C++ ipp files

Hoping you had a nice holiday break, it is now the time to resume our series on header files with a new topic covering the world of template definitions in C++. If you have ever used the Boost libraries, you may have noticed that aside from the regular hpp header files, they also provide a bunch of accompanying ipp files. ipp files, in the general case, are used to provide the implementation for a template class defined in a corresponding hpp file.

December 2, 2013 · Tags: cxx, header-files
Continue reading (about 2 minutes)

Header files: Self-containment

The rule The mere fact of including a given header file, without including any other beforehand, should not be enough of a reason for the build to break. This means that the header file should be self-contained, and for this to be the case, such header file has to pull in any dependencies that it explicitly requires (and no more). Interestingly, note that this does not mean that a header file must include everything it may ever need to be fully usable.

November 25, 2013 · Tags: header-files
Continue reading (about 4 minutes)

Header files: Multiple-inclusion protection

Let’s start the series with something simple: the basic structure of header files and why and how to protect against multiple inclusion. The rule The basic use of header files is to provide symbol declarations for functions and globals. Because multiple declarations of a given symbol in a single translation unit are a syntax error, you have to defensively structure your header files to not redefine anything in case they are included multiple times.

November 21, 2013 · Tags: header-files
Continue reading (about 3 minutes)

Header files: Series introduction

As I started typing a supposedly-simple post on header files, I realized that what I was explaining could easily be split into various posts and significantly extended with additional content, so here comes a new (short) series on these special little files in the need of careful attention. Quoting the Wikipedia: A header file is a file that allows programmers to separate certain elements of a program’s source code into reusable files.

November 18, 2013 · Tags: header-files
Continue reading (about 2 minutes)