Why we are saving a file as .cpp or .c
Why is the source file extension cpp or c
Collapse
X
-
Tags: None
-
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.Comment
-
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).Comment
Comment