cpp or cc extension?

Discussion in 'C++' started by Johs, Apr 19, 2007.

  1. Johs

    Johs Guest

    I have read various tutorials on the net on c++ and sometimes they use
    ..cc as extension to files and other times they use .cpp or even just .c.
    Are there no strict rules for naming of sourcefiles?
     
    Johs, Apr 19, 2007
    #1
    1. Advertising

  2. Johs

    Zeppe Guest

    Johs wrote:
    > I have read various tutorials on the net on c++ and sometimes they use
    > .cc as extension to files and other times they use .cpp or even just .c.
    > Are there no strict rules for naming of sourcefiles?


    There are no strict rules AFAIK, but there are de-facto standard. That is:
    - c source files: c
    - c header files: h
    - c++ source files: cpp, cc, cxx
    - c++ header files: h, hh, hpp

    at least for the most common. I won't use the c extension for a cpp
    program, because many compilers that compile both c and c++ interpret
    the file as a c source if it has the c extension. For the header files
    there is any problem indeed because the keep the context of the
    translation unit in which they are included.

    Regards,

    Zeppe
     
    Zeppe, Apr 19, 2007
    #2
    1. Advertising

  3. Zeppe wrote:
    > Johs wrote:
    >> I have read various tutorials on the net on c++ and sometimes they
    >> use .cc as extension to files and other times they use .cpp or even
    >> just .c. Are there no strict rules for naming of sourcefiles?

    >
    > There are no strict rules AFAIK, but there are de-facto standard.
    > That is:
    > - c source files: c
    > - c header files: h
    > - c++ source files: cpp, cc, cxx


    In the early days (and maybe just to be difficult^H^H^H^H^Herent),
    Unix used .C (capital C) extension for C++ files. Since MS operating
    systems have case insensitive file names, copying .C files from the
    Web to a Windows-run system loses the distinction between .c and .C
    files. If you know that it's a C++ source, rename it to .cpp right
    away.

    > - c++ header files: h, hh, hpp
    >
    > at least for the most common. I won't use the c extension for a cpp
    > program, because many compilers that compile both c and c++ interpret
    > the file as a c source if it has the c extension. For the header files
    > there is any problem indeed because the keep the context of the
    > translation unit in which they are included.


    Case insensitivity is a bliss, ain't it?

    V
    --
    Please remove capital 'A's when replying by e-mail
    I do not respond to top-posted replies, please don't ask
     
    Victor Bazarov, Apr 19, 2007
    #3
  4. Johs

    James Kanze Guest

    On Apr 19, 2:12 pm, Zeppe
    <> wrote:
    > Johs wrote:
    > > I have read various tutorials on the net on c++ and sometimes they use
    > > .cc as extension to files and other times they use .cpp or even just .c.
    > > Are there no strict rules for naming of sourcefiles?


    > There are no strict rules AFAIK, but there are de-facto standard. That is:
    > - c source files: c
    > - c header files: h
    > - c++ source files: cpp, cc, cxx
    > - c++ header files: h, hh, hpp


    > at least for the most common. I won't use the c extension for a cpp
    > program, because many compilers that compile both c and c++ interpret
    > the file as a c source if it has the c extension. For the header files
    > there is any problem indeed because the keep the context of the
    > translation unit in which they are included.


    Historically, the original suffix for C++ was .C. Which, of
    course, poses problems on systems which don't distinguish case
    in filenames (most of them, I think---at least, I've never
    encountered any but Unix which do distinguish case). For
    whatever reasons, the convention seems to have become
    established of using .cpp in the Windows world, whereas .cc
    seems more frequent (but not exclusive) under Unix.

    All of the compilers I know will treat either as a C++ source in
    their most recent incarnations, and all have always had an
    option to force treating the source as C++. Just be consistent,
    and don't worry about it.

    The conventions for header files are even vaguer. The original
    convention was just to use .h, and not distinguish them from C
    header files. Apparently, I wasn't the only one who didn't like
    this, and a lot of people adopted different rules: .H, .hpp or
    ..hh. Again, just be consistent (although I do think it better
    to restrict .h to headers which can be used within a C program
    as well).

    --
    James Kanze (GABI Software) email:
    Conseils en informatique orientée objet/
    Beratung in objektorientierter Datenverarbeitung
    9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
     
    James Kanze, Apr 19, 2007
    #4
  5. Johs

    Zeppe Guest

    James Kanze wrote:

    > The conventions for header files are even vaguer. The original
    > convention was just to use .h, and not distinguish them from C
    > header files. Apparently, I wasn't the only one who didn't like
    > this, and a lot of people adopted different rules: .H, .hpp or
    > .hh. Again, just be consistent (although I do think it better
    > to restrict .h to headers which can be used within a C program
    > as well).


    Just to add a final note on this, some graphical editors can decide to
    highlight .h files as "c source" and .hpp files as "c++ source".

    Bye!

    Zeppe
     
    Zeppe, Apr 19, 2007
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DrUg13
    Replies:
    1
    Views:
    482
    DrUg13
    Feb 10, 2004
  2. Alex Vinokur
    Replies:
    7
    Views:
    414
    Greg Comeau
    Nov 15, 2004
  3. Vinu
    Replies:
    9
    Views:
    627
  4. Anand
    Replies:
    3
    Views:
    903
    Tim Daneliuk
    Nov 8, 2003
  5. www.hitechskill.com
    Replies:
    0
    Views:
    1,361
    www.hitechskill.com
    Apr 9, 2006
Loading...

Share This Page