473,414 Members | 1,577 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

cpp or cc extension?

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?
Apr 19 '07 #1
4 23990
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
Apr 19 '07 #2
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
Apr 19 '07 #3
On Apr 19, 2:12 pm, Zeppe
<zeppe.remove.all.this.long.comm...@email.itwrot e:
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:ja*********@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

Apr 19 '07 #4
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
Apr 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Gyger | last post by:
Hello, Three weeks ago, I have started to develop a binding extension for Qt and PHP 5. Now, I can display a dialog box containing some widgets like label, buttons and edit line. I have just...
8
by: Torsten Mohr | last post by:
Hi, i write an extension module in C at the moment. This module does some work on some own data types that consist of some values. The functions that can change the data are written in C. ...
3
by: man-in-nature | last post by:
Hello, I have already read several existing posts about xsd:extension, but do not find something useful to my test case. I have one xml file and one xsd file. I can use a simple command line...
5
by: Jeffry van de Vuurst | last post by:
Hi, I'm working on an xml schema and I'm running into some problems relating substitutionGroups and extensions. This xsd validates fine: There are three elements and three complex types and...
7
by: Adam | last post by:
Im trying to add an httphandler for all *.sgf file extensions. I have developed the handler, 1. installed it into the gac 2. added it to the machine.config: <httpHandlers> <add verb="*"...
4
by: pepcag | last post by:
I used http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconalteringsoapmessageusingsoapextensions.asp as a template to create a very simple web method with soap...
1
by: Brian Henry | last post by:
Just thought maybe someone here would like to know this. It's an example code I just created quickly on how to figure out the name of a type of file based on its extension (say for example .DOC)...
0
by: robert | last post by:
Hi all, I'm having a hard time resolving a namespace issue in my wsdl. Here's an element that explains my question, with the full wsdl below: <definitions name="MaragatoService"...
6
by: tommybiegs | last post by:
I'm having a weird problem. I can't seem to force php to load an extension using php.ini, but it loads perfectly if I use dl() at the beginning of a test script. In php.ini I've got: ...
1
Ganesh9u
by: Ganesh9u | last post by:
Hi All, import org.sf.feeling.swt.win32.extension.hook.Hook; import org.sf.feeling.swt.win32.extension.hook.data.HookData; import org.sf.feeling.swt.win32.extension.hook.data.MouseHookData; ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.