James Kanze
11/27/2008 10:24:00 PM
On Nov 27, 10:13 pm, Erik Wikström <Erik-wikst...@telia.com> wrote:
> On 2008-11-27 20:44, Patrick Brehmer wrote:
> > What is the difference between the two pairs of extensions?
> > A long time I know I only .h + .cpp
> Which is probably what most people use.
I don't know about that. Every place I've worked has kept .h
for C headers, and used .hh for C++ (and .cc for the source
files). Under Windows, what little I've seen it was .hpp for
C++ headers, and .cpp for source files. (And back under MS-DOS,
there was also some .hxx and .cxx. And the original C++
implementations used .C for the source files.)
> > When and why was the other pair introduced?
> The C pre-processor (which is very similar to the C++
> pre-processor) is also commonly referred to as CPP which might
> cause some confusion in certain circumstances (especially if
> you output the pre-processed files with .cpp as suffix), which
> might be one reason to use .cxx/.hxx.
> Some people also make a distinction between .h and .hpp where
> the latter is used for templates, i.e. they do not just
> contain the interface, but also the implementation.
No. The distinction is that a .h file can be used in a C
program; a .hpp can't. When template implementations are kept
separate, they usually receive a different suffix entirely; I've
seen .tcc in several contexts. (And in earlier times, I've seen
..ihh for the implementation of inline functions.)
> > Can I mix them in one and the same project?
> Yes, but I would recommend that you choose one convention and
> use it for all files, and unless you have any reason not to I
> think .cpp/.h is the best.
Unless you're really a 100% Windows shop, I think you're going
to have to deal with different conventions, because different
third party libraries will use different conventions. I use
..hh/.cc, because that is what my customers do; globally, I
suspect that .hpp/.cpp is more widely used, however.
One thing is certain, however: you don't want to use .h unless
the header can be used in a C program.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34