.c, .cpp, .h 외의 확장자들 : .cxx, .hpp C/C++

요약하자면, c가 아닌 c++ 스타일로 정의된 헤더파일은 그것이 c++ 스타일임을 명시해 주어야 할 필요가 있기 때문에 .hpp와 같이 다른 확장자를 사용함으로서 이를 알 수 있게 한다.

cxx와  cpp는 같다고 생각한다.

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
      Represents the flags passed to the pre-processor.
    • CFLAGS
      Flags passed to the C compiler.
      Flags passed to the C++ compiler.
      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


댓글 입력 영역