Why is the source file extension cpp or c

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shylubaskar
    New Member
    • Nov 2008
    • 3

    #1

    Why is the source file extension cpp or c

    Why we are saving a file as .cpp or .c
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by shylubaskar
    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

    Comment

    • r035198x
      MVP
      • Sep 2006
      • 13225

      #3
      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

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        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

        Working...