Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > cpp or cc extension?

Reply
Thread Tools

cpp or cc extension?

 
 
Johs
Guest
Posts: n/a
 
      04-19-2007
I have read various tutorials on the net on c++ and sometimes they use
..cc as extension to files and other times they use .cpp or even just .c.
Are there no strict rules for naming of sourcefiles?
 
Reply With Quote
 
 
 
 
Zeppe
Guest
Posts: n/a
 
      04-19-2007
Johs wrote:
> I have read various tutorials on the net on c++ and sometimes they use
> .cc as extension to files and other times they use .cpp or even just .c.
> Are there no strict rules for naming of sourcefiles?


There are no strict rules AFAIK, but there are de-facto standard. That is:
- c source files: c
- c header files: h
- c++ source files: cpp, cc, cxx
- c++ header files: h, hh, hpp

at least for the most common. I won't use the c extension for a cpp
program, because many compilers that compile both c and c++ interpret
the file as a c source if it has the c extension. For the header files
there is any problem indeed because the keep the context of the
translation unit in which they are included.

Regards,

Zeppe
 
Reply With Quote
 
 
 
 
Victor Bazarov
Guest
Posts: n/a
 
      04-19-2007
Zeppe wrote:
> Johs wrote:
>> I have read various tutorials on the net on c++ and sometimes they
>> use .cc as extension to files and other times they use .cpp or even
>> just .c. Are there no strict rules for naming of sourcefiles?

>
> There are no strict rules AFAIK, but there are de-facto standard.
> That is:
> - c source files: c
> - c header files: h
> - c++ source files: cpp, cc, cxx


In the early days (and maybe just to be difficult^H^H^H^H^Herent),
Unix used .C (capital C) extension for C++ files. Since MS operating
systems have case insensitive file names, copying .C files from the
Web to a Windows-run system loses the distinction between .c and .C
files. If you know that it's a C++ source, rename it to .cpp right
away.

> - c++ header files: h, hh, hpp
>
> at least for the most common. I won't use the c extension for a cpp
> program, because many compilers that compile both c and c++ interpret
> the file as a c source if it has the c extension. For the header files
> there is any problem indeed because the keep the context of the
> translation unit in which they are included.


Case insensitivity is a bliss, ain't it?

V
--
Please remove capital 'A's when replying by e-mail
I do not respond to top-posted replies, please don't ask


 
Reply With Quote
 
James Kanze
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 2:12 pm, Zeppe
<(E-Mail Removed)> wrote:
> Johs wrote:
> > I have read various tutorials on the net on c++ and sometimes they use
> > .cc as extension to files and other times they use .cpp or even just .c.
> > Are there no strict rules for naming of sourcefiles?


> There are no strict rules AFAIK, but there are de-facto standard. That is:
> - c source files: c
> - c header files: h
> - c++ source files: cpp, cc, cxx
> - c++ header files: h, hh, hpp


> at least for the most common. I won't use the c extension for a cpp
> program, because many compilers that compile both c and c++ interpret
> the file as a c source if it has the c extension. For the header files
> there is any problem indeed because the keep the context of the
> translation unit in which they are included.


Historically, the original suffix for C++ was .C. Which, of
course, poses problems on systems which don't distinguish case
in filenames (most of them, I think---at least, I've never
encountered any but Unix which do distinguish case). For
whatever reasons, the convention seems to have become
established of using .cpp in the Windows world, whereas .cc
seems more frequent (but not exclusive) under Unix.

All of the compilers I know will treat either as a C++ source in
their most recent incarnations, and all have always had an
option to force treating the source as C++. Just be consistent,
and don't worry about it.

The conventions for header files are even vaguer. The original
convention was just to use .h, and not distinguish them from C
header files. Apparently, I wasn't the only one who didn't like
this, and a lot of people adopted different rules: .H, .hpp or
..hh. Again, just be consistent (although I do think it better
to restrict .h to headers which can be used within a C program
as well).

--
James Kanze (GABI Software) email:(E-Mail Removed)
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

 
Reply With Quote
 
Zeppe
Guest
Posts: n/a
 
      04-19-2007
James Kanze wrote:

> The conventions for header files are even vaguer. The original
> convention was just to use .h, and not distinguish them from C
> header files. Apparently, I wasn't the only one who didn't like
> this, and a lot of people adopted different rules: .H, .hpp or
> .hh. Again, just be consistent (although I do think it better
> to restrict .h to headers which can be used within a C program
> as well).


Just to add a final note on this, some graphical editors can decide to
highlight .h files as "c source" and .hpp files as "c++ source".

Bye!

Zeppe


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Free online test in C, CPP / Placement papers / CPP,C Interview Questions www.hitechskill.com C++ 0 04-09-2006 10:53 AM
when i compile the cpp file(cmdargs.cpp) int main(int argc, wchar_t* argv[]) Vinu C++ 9 05-05-2005 04:11 AM
calling cpp file from c# Ohad ASP .Net 1 01-05-2005 03:18 AM
Method inlined in source1.cpp and called in source2.cpp Alex Vinokur C++ 7 11-15-2004 09:14 PM
What is better /standard for creating files. a cpp file with header or cpp and seperate file for header DrUg13 C++ 1 02-10-2004 09:20 AM



Advertisments