[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.c++

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

p.brehmer

11/27/2008 7:44:00 PM

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

12 Answers

.rhavin grobert

11/27/2008 7:50:00 PM

0

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:

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

11/27/2008 7:56:00 PM

0

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


--
Christian Hackl

Erik Wikström

11/27/2008 9:13:00 PM

0

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

11/27/2008 9:34:00 PM

0

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

11/27/2008 10:24:00 PM

0

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

James Kanze

11/27/2008 10:26:00 PM

0

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

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

Juha Nieminen

11/27/2008 10:55:00 PM

0

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

11/28/2008 1:35:00 PM

0

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
>

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

Bart van Ingen Schenau

11/28/2008 4:01:00 PM

0

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

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...
c.l.c FAQ: http://...
c.l.c++ FAQ: http://www.parashift.com/c++...

nick

11/29/2008 4:31:00 PM

0

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
>

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