473,587 Members | 2,547 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 24017
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.a ll.this.long.co mm...@email.itw rote:
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 objektorientier ter Datenverarbeitu ng
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
4614
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 implemented some Qt classes (not completly) like QApplication, QObject, QWidget, Qlabel, QLineEdit and QGrid just to test some very simple...
8
2753
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. The question came up if this is by itself thread safe, if some two or more threads try to change these data types, are the C functions by themselves...
3
2054
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 (C#) program to validate the xml file against the xsd file without any error. The problem is that when I validate the same xml file within VisualStudio...
5
3378
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 every element has the type of some complexType. <?xml version="1.0" encoding="UTF-8"?>
7
2909
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="*" path="*.sgf" type="CustomExtensionHandler, Extenders.CustomExtensionHandler, Version=1.0.0.0, Culture=neutral, PublicKeyToken=d831d925597c1031"...
4
6010
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 extension. The code like this: public string HelloWorld() { return "Hello World.";
1
2162
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) would return "Microsoft Word Document"... tired doing this before with SHGetFileInfo or what ever its called, but that seemed to require a phyiscal...
0
2130
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" targetNamespace="http://swaMaragatoNS" xmlns:tns="http://swaMaragatoNS" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"...
6
4208
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: extension_dir = "/correct/verified/path/to/extension/dir/" extension=imagick.so Apache will not restart if both those lines are present in php.ini
1
4344
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; import org.sf.feeling.swt.win32.extension.hook.listener.HookEventListener; public class HotMouse {
0
7920
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7849
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8347
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7973
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6626
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5394
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1454
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.