By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,502 Members | 1,620 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,502 IT Pros & Developers. It's quick & easy.

Why is the source file extension cpp or c

P: 3
Why we are saving a file as .cpp or .c
Nov 12 '08 #1
Share this Question
Share on Google+
3 Replies


Expert 10K+
P: 11,448
Why we are saving a file as .cpp or .c
It's just a convention: .cpp for the cplusplus (c++) files and .c for the c files. Some
programs rely on it.

kind regards,

Jos
Nov 12 '08 #2

10K+
P: 13,264
The .cpp is usually used for c++ source files while the .c is used for C source file.
Note though that most compilers have flags to tell them to compile as C or C++ so the extension is really just aesthetic.

EDIT: Looks like Jos just got a new (faster) keyboard.
Nov 12 '08 #3

Banfa
Expert Mod 5K+
P: 8,916
Note that while C tended to use just .c and .h for it's file extensions there are many other extensions in use in C++ on top of .cpp, for instance .cxx, .hpp, .hxx, .cc to name a few.

The extension is really only for your personal use, for instance some people use .hpp for C++ headers, in the same way that .c for C source became .cpp for C++ source they transformed .h for C headers to .hpp for C++ headers.

I don't I still use .h for all (well most) headers. On the other hand I do use .hxx (or occasionally .cxx) when I am create a template class (so I have a visual clue from the file name).

The extensions you use are your own choice. However most compilers by default compile .c as C and .cpp as C++, as r035198x says this can normally be over ridden by compiler switches (and I have done that to force C++ compilation on some auto generated C source).
Nov 12 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.