CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    May 2002
    Posts
    1,798

    What's with *.cxx files instead of *.cpp?

    I occasionally come across source code that contains a mixture of *.cpp and *.cxx files.

    Why do people do that ? What's the point ? How are they different? They seem the same to me.

    I get the feeling that such source code has been ported from Fortran or some other 'academic' language.

    What's the scoop?

    Mike
    mpliam

  2. #2
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: What's with *.cxx files instead of *.cpp?

    CXX and CPP are same with VC++, aparently the C++ source files were supposed to be .c++ but as few file systems dont allow + in extension, then it is said that x was used to mimic +, that how it became .cXX, not anyway different though.
    Regards,
    Ramkrishna Pawar

  3. #3
    Join Date
    Feb 2005
    Location
    Normandy in France
    Posts
    4,590

    Re: What's with *.cxx files instead of *.cpp?

    Quote Originally Posted by Mike Pliam
    I occasionally come across source code that contains a mixture of *.cpp and *.cxx files.
    It is probably due to a project using libraries (in form of source code) that don't use the same naming convention the programmer(s) of the project.

    There are at least four different extensions usable for C++ files:
    • .C
      Not very popular since it requires a case-sensitive file system (otherwise, it would clash with old .c file names), and even a few modern OS are not case-sensitive.
    • .c++
      Some OS or file systems don't support the + character in file names.
    • .cpp
      That's very portable across file systems.
      But, it might be less consistent than .cxx
    • .cxx
      Very portable across file systems (not more than .cpp)
      Using the name CXX for C++ is quite popular because CPP usually designates the C (and C++) pre-processor.
      For example, these environment variables/makefile macros
      • CPPFLAGS
        Represents the flags passed to the pre-processor.
      • CFLAGS
        Flags passed to the C compiler.
      • CXXFLAGS
        Flags passed to the C++ compiler.
      • LDFLAGS
        Flags passed to the linker.
      • CC
        The path to the C compiler.
      • CPP
        The path to the pre-processor.
      • CXX
        The path to the C++ compiler.
      • LD
        The path to the linker.

      That's why, with the above notations, it's very natural to give the .cxx extension to C++ files.


    For headers, there are at least five extensions:
    • .h
      Traditional C header files.
      Since the compiler doesn't do anything based on this extension, it can be used for C++ header files too.
      Furthermore, there are a lot of header files that are designed to be included by both C and C++ translation units.
      In that case, it's natural to give them this extension.
    • .H, .hpp or .hxx
      That's very natural to give one of these extensions for C++ header files (being consistent with the name of C++ translation units).
      That's not a bad idea to use one of these name for pure C++ header files only (containing class definitions, or templates, or any other feature not supported by C).
    • No extension
      That's internally used by a number of C++ compilers for iostream, vector, algorithm and all others new-style C++ headers.

    There are probably other (less popular) extensions for headers.
    Perhaps .cpp and .i
    "inherit to be reused by code that uses the base class, not to reuse base class code", Sutter and Alexandrescu, C++ Coding Standards.
    Club of lovers of the C++ typecasts cute syntax: Only recorded member.

    Out of memory happens! Handle it properly!
    Say no to g_new()!

  4. #4
    Join Date
    May 2002
    Posts
    1,798

    Wink Re: What's with *.cxx files instead of *.cpp?

    Thanks for the info.

    I dont know squat about programming Unix systems, but I do believe that most of the *.cxx and *.hxx files that I have encountered were originally intended for use with Unix mak files. And academic institutions seem to gravitate to Unix. Because I can never get those mak files to work properly, I have developed a hostile, mistrusting attitute towards them.

    Sorry. I realize this isnt a psychotherapy session.

    Regards.

    Mike
    mpliam

  5. #5
    Join Date
    Oct 2000
    Location
    London, England
    Posts
    4,773

    Re: What's with *.cxx files instead of *.cpp?

    I use .hpp and .hxx differently. .hpp files are exported headers, .hxx are internal headers local only to the module.

    .hh and .cc are also used - for auto-generated source. CORBA IDL compiler for example produces .cc and .hh files. It's useful when you see these headers to know that a program generated them.

    .h is popular for headers even in C++ although it's possibly best reserved for C-compatible headers. Often used for entry points to DLL. In a shared-object, all the symbols are exported but you can still use a .h file to publish the entry points from a C-interface so that a C client can use the library. A .h file can also be used for declarations of enums and constants.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured