Showing 9 posts
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. In particular, I do not have any more “post series” in the queue so upcoming posts will be more varied in content! Hope you will enjoy them anyway.
January 1, 2014
·
Tags:
<a href="/tags/header-files">header-files</a>
Continue reading (about
1 minute)
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. I felt that such article fit these series perfectly well, so here it goes.
December 30, 2013
·
Tags:
<a href="/tags/header-files">header-files</a>
Continue reading (about
1 minute)
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:
<a href="/tags/header-files">header-files</a>
Continue reading (about
2 minutes)
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). In other words: the effect of importing a module is simply getting a single reference to that module.
December 9, 2013
·
Tags:
<a href="/tags/header-files">header-files</a>
Continue reading (about
4 minutes)
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. (It may have come into existence to simplify the porting of old, non-ISO C++ code to modern C++, but that’s just a guess.)
December 5, 2013
·
Tags:
<a href="/tags/cxx">cxx</a>, <a href="/tags/header-files">header-files</a>
Continue reading (about
3 minutes)
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. This stems from the fact that, in C++, the code for such template definitions must be available whenever the class is instantiated, and this in turn means that the template definitions cannot be placed in separate modules as is customary with non-template classes. In other words: putting the template definitions in cpp files just does not work. (I hear the C++ standards committee wants to “fix” this but I forget the details now and cannot find a reference.)
December 2, 2013
·
Tags:
<a href="/tags/cxx">cxx</a>, <a href="/tags/header-files">header-files</a>
Continue reading (about
2 minutes)
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:
<a href="/tags/header-files">header-files</a>
Continue reading (about
4 minutes)
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:
<a href="/tags/header-files">header-files</a>
Continue reading (about
3 minutes)
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. Header files commonly contain forward declarations of classes, subroutines, variables, and other identifiers. Programmers who wish to declare standardized identifiers in more than one source file can place such identifiers in a single header file, which other code can then include whenever the header contents are required. This is to keep the interface in the header separate from the implementation.
November 18, 2013
·
Tags:
<a href="/tags/header-files">header-files</a>
Continue reading (about
2 minutes)