Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

What is the difference between .cpp + .h vs .cxx and .hxx ?

2,294 views
Skip to first unread message

Patrick Brehmer

unread,
Nov 27, 2008, 2:44:08 PM11/27/08
to
What is the difference between the two pairs of extensions?
A long time I know I only .h + .cpp

When and why was the other pair introduced?

Can I mix them in one and the same project?

Patrick

.rhavin grobert

unread,
Nov 27, 2008, 2:50:11 PM11/27/08
to

i think it's just convenience to have:

.c : c-implementation
.h : header in c-style or pimpl-header
.cpp : c++-implementation
.hpp : c++-header or implementation header
.cxx : c# implementation
.hxx : c#-header

Christian Hackl

unread,
Nov 27, 2008, 2:55:35 PM11/27/08
to
.rhavin grobert ha scritto:

> On 27 Nov., 20:44, p.breh...@gmx.net (Patrick Brehmer) wrote:
>> What is the difference between the two pairs of extensions?
>> A long time I know I only .h + .cpp
>>
>> When and why was the other pair introduced?
>>
>> Can I mix them in one and the same project?
>>
>> Patrick
>
> i think it's just convenience to have:

Correct, it's just a matter of conventions. See the FAQ:

http://www.parashift.com/c++-faq-lite/coding-standards.html#faq-27.8


--
Christian Hackl

Erik Wikström

unread,
Nov 27, 2008, 4:13:00 PM11/27/08
to
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.

> 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.

> 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.

PS: In C# there are no header-files and .cs is usually used as suffix.

--
Erik Wikström

Ulrich Eckhardt

unread,
Nov 27, 2008, 4:34:11 PM11/27/08
to
Patrick Brehmer wrote:
> What is the difference between the two pairs of extensions?
> A long time I know I only .h + .cpp

This is purely conventional. Further, some compilers decide whether
something is C or C++ based on the extension.

> Can I mix them in one and the same project?

Yes. You can name you file whatever you want. In some cases, you will have
to tell the compiler what it is supposed to be and your editor's
highlighting won't work but technically, there are no differences.

Further C++ suffixes are btw .cc, .C (capital c!), .c++ and .hpp.

Uli

James Kanze

unread,
Nov 27, 2008, 5:24:08 PM11/27/08
to
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...@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

James Kanze

unread,
Nov 27, 2008, 5:26:23 PM11/27/08
to
On Nov 27, 10:34 pm, Ulrich Eckhardt <dooms...@knuut.de> wrote:
> Patrick Brehmer wrote:
> > What is the difference between the two pairs of extensions?
> > A long time I know I only .h + .cpp

> This is purely conventional. Further, some compilers decide
> whether something is C or C++ based on the extension.

It goes beyond C or C++: .f is Fortran, etc. You can usually
override this, however, and all modern compilers recognize a
number of extensions as C++ (.cpp and .cc, at least, generally
.cxx as well, and under Unix, .C).

Juha Nieminen

unread,
Nov 27, 2008, 5:54:54 PM11/27/08
to
.rhavin grobert wrote:
> i think it's just convenience to have:
>
> .c : c-implementation
> .h : header in c-style or pimpl-header
> .cpp : c++-implementation
> .hpp : c++-header or implementation header
> .cxx : c# implementation
> .hxx : c#-header

In the unix world, especially when using gcc, it has been customary to
use the extensions:

.cc : C++ implementation
.hh : C++ header

I think it's stupid to use ".h" for C++ headers. ".h" should be
reserved for C headers. Using it for C++ headers only causes confusion
in both people and programs (at least editors with code coloring).

Francis Glassborow

unread,
Nov 28, 2008, 8:34:54 AM11/28/08
to

you can use any extension you like as far as C++ is concerned but your
tools may attribute particular extensions.

Bart van Ingen Schenau

unread,
Nov 28, 2008, 11:01:28 AM11/28/08
to
Patrick Brehmer wrote:

File extensions are not specified by either the C or the C++ language.
There are some widely followed conventions (such as using the name of
the language, or just the first letter), but they don't work nicely for
C++ for several reasons:
- The extension .c was already in use for C
- Many operating systems do/did not look kindly on strange characters,
such as +, in filenames, so .c++ could also not be used universally.
- Some systems use .C, but that can not be used everywhere (for example,
Windows is case-insensitive, so it would conflict with the extension
for C code)
In the end, nobody could agree on the proper file extension for C++
code, so several are in use with different compilers.

If your compiler automatically recognises the file extensions .cpp
and .cxx as referring to C++ code, you can mix those freely in a
project. (Although I would not recommend it. Consistency is good.)
If your compiler does not recognise .cxx as C++ code, you can either
rename your files or try to tell the compiler how to interpret those
files.

Bart v Ingen Schenau
--
a.c.l.l.c-c++ FAQ: http://www.comeaucomputing.com/learn/faq
c.l.c FAQ: http://c-faq.com/
c.l.c++ FAQ: http://www.parashift.com/c++-faq-lite/

nick

unread,
Nov 29, 2008, 11:30:37 AM11/29/08
to

it is compiler dependent but with some compilers you can even make a
file names blank.notcpp and include it by saying

#include <blank.notcpp>

however its good programing practice to choose the extention that makes
the most sence. i usualy just use .cpp and .h however headers can alos
be .hpp, c++ files can still be in a .c file if the compliler is c++...

Daniel T.

unread,
Nov 30, 2008, 8:59:55 AM11/30/08
to
p.br...@gmx.net (Patrick Brehmer) wrote:

The answers to your questions depend on the compiler.

岳信明

unread,
Dec 5, 2008, 2:46:09 AM12/5/08
to

no difference between them, you can use anyone or mixture of them.

sakshi singh

unread,
Jul 8, 2022, 1:29:05 AM7/8/22
to
A rehabilitation centre is a place where people with physical or mental disabilities can go to improve their condition. The staff at a rehabilitation centre will help the patients regain their strength and mobility. They will also teach them how to cope with their disability. The patients will be given a chance to socialize with other people at the centre. They will also be able to participate in activities that will help them mentally and emotionally.

https://bit.ly/3P81zZz
https://bit.ly/3ypNaBt
https://bit.ly/3IiB3e5
https://bit.ly/3aj7agW
https://bit.ly/3Ax5DhX
https://bit.ly/3anB4Rm
https://bit.ly/3yreGi5
https://bit.ly/3yKo9lR
https://bit.ly/3apDiQg
https://bit.ly/3AybpzX
https://bit.ly/3ABuJwe
https://bit.ly/3NPl7AU
https://bit.ly/3NNQyvI
https://bit.ly/3NJimBe
0 new messages