4

Possible Duplicate:
Correct C++ code file extension? .cc vs .cpp
.c vs .cc vs. .cpp vs .hpp vs .h vs .cxx

I have written C++ code in files with extension .cpp, .cc or .cxx

Can anyone explain that what is the difference between these three and which one is the best ( is that platform dependent ) and why?

I am currently working on cygwin.

Community
  • 1
  • 1
Rog Matthews
  • 3,147
  • 16
  • 37
  • 56
  • You can find some information [here](http://stackoverflow.com/questions/1545080/correct-c-code-file-extension-cc-vs-cpp) – Alexander Feb 22 '12 at 12:01
  • All three are possible extension for C++. You could also use .C (capital c) if you wish. There's no *best* one. Pick one that your editor and compiler toolchain (e.g. tools around compiler) knows. – Didier Trosset Feb 22 '12 at 12:02
  • 1
    Interesting trivia albeit not exactly in-line with the OP, with g++ it doesn't matter what the extension is. .c, .cpp, .cxx, .h, .hxx, .hpp - it'll compile anything you feed it. .foo, .bar. etc. – synthesizerpatel Feb 22 '12 at 12:07

4 Answers4

6

It's a matter of code conventions. These extensions are all interchangeable (as far as platforms are concerned). If you participate in an existing project, you should adhere to this project's conventions, otherwise just choose whatever you like.

user1071136
  • 15,636
  • 4
  • 42
  • 61
3
  • The .cpp extension used to mean C PreProcessor but nowadays is often used for C++. However, I'd avoid it due to the older meaning.
  • .c++ is pretty obvious, but some people avoid it since the plus might be a special character in some shells which you would need to escape, IIRC.
  • .cxx is the "compromise", think rotating a plus by 45 degrees.
  • I've not seen .cc very often, YMMV.

But at the end of the day you could pick whichever extension you like, even .c-plus-plus, since the compiler doesn't care. So go with the one you like the best. As always with coding, if you're working in an existing project stick to the convention that's already established there.

DarkDust
  • 90,870
  • 19
  • 190
  • 224
1

They are just different conventions; none is better than the others or has any special meaning relative to the others. Often people will name headers using the same associated convention: .h or .hxx or .hpp. Just be consistent, and it doesn't matter which one you use.

Ernest Friedman-Hill
  • 80,601
  • 10
  • 150
  • 186
1

There is no difference at all. Its not platform dependent. You can use any of them.

omggs
  • 1,163
  • 1
  • 11
  • 23