Correct C ++ file extension

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

I wrote C ++ code in files with the extension .cpp , .cc or .cxx

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

I am currently working on cygwin.

+3
source share
4 answers

This is a matter of code conventions. These extensions are interchangeable (for platforms). If you are participating in an existing project, you must adhere to these project conventions, otherwise just choose what you like.

+5
source
  • The .cpp extension used to refer to C PreProcessor, but is currently often used for C ++. However, I would avoid this because of the older meaning.
  • .c++ pretty obvious, but some people shy away from it, since the plus may be a special character in some shells that you will need to avoid, IIRC.
  • .cxx is a "compromise" involving a plus turn of 45 degrees.
  • I have not seen .cc very often, YMMV.

But at the end of the day, you can choose any extension that you like, even .c-plus-plus , since the compiler doesn't care. So go with the one you like best. As always with coding, if you are working in an existing project, stick to an already established agreement.

+2
source

These are just different conventions; no one is better than others or has any special significance in relation to others. Often people name headers using the same associated convention: .h or .hxx or .hpp . Just be consistent and it doesn't matter which one you use.

+1
source

There is no difference. Its platform independent. You can use any of them.

+1
source

Source: https://habr.com/ru/post/1494641/


All Articles