Tutorial :Is there any reason Google uses the cc extension instead of cpp in their open source projects?



Question:

Is there any reason Google uses the cc extension instead of the standard cpp in their open source projects? Should I do that too?


Solution:1

It's entirely a matter of personal preference, at least for the person(s) starting the project. Whatever you choose, be consistent.


Solution:2

There are 4 main extensions used for C++ source code:

  • .C (upper-case C)
  • .cpp
  • .cxx
  • .cc

Choose whichever makes the most sense for you, and expect to have to deal with problems on some other platforms.

Of these choices, the one I listed first is most problematic. Both Windows and MacOS X (by default) have case-preserving but case-insensitive file systems. That means that 'file.c' and 'file.C' (and, indeed, 'FILE.C') are names for the same file.

If you have plans to work with Google code, you might want to follow the Google convention.


Solution:3

Consistency. Nothing more. The extensions ".cpp", ".cxx", ".cc", and ".C" are all valid extensions for C++ source files (although you should avoid ".C" as it can lead to problems on filesystems that are case-insensitive but case-preserving, like those of Mac OS X and Windows). Similarly, ".h" and ".hpp" are common extensions for C++ headers. In my experience ".cpp" and ".h" are the most common, and those are the ones that I would typically recommend for new projects. If you are adding to an existing project, you should use whatever convention exists for that project (e.g. you would use ".hpp" in Boost).


Solution:4

There is no standard extension for C++ source files. There are some commonly used extensions but you're free to use any that you want assuming your toolset supports it (don't know of one that doesn't). You could postfix all your C++ source files with .html if you wanted.


Solution:5

Typing .cc is quite a bit easier than .cpp, and for all other purposes they're equivalent. So, yes.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »