Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

JAVA ONLY! C++ code is divided into two different file types. Header file which

ID: 3832052 • Letter: J

Question

JAVA ONLY!

C++ code is divided into two different file types. Header file which holds class and functions deceleration. Header files usually have the following extensions, .h, .hpp, and .hxx. Source file which holds the actual definition of class and functions. Source files usually have the following extensions, .C, .cpp, and .cxx.

One of the difficulties that C++ programmers have is include file pollution. This means that a Source file and/or Header file includes same Header file or one Header file is included multiple times by other Header files.

For example:

myProject1/
- Class1.hpp - Class1.cpp - Class2.hpp - Class2.cpp - Main.cpp

Class2.hpp includes Class1.hpp
Main.cpp includes Class1.hpp and Class2.hpp

Hint: You can use java.util.regex. in your code.

Your task is to create an application which searches through all Source and Header files in another project and outputs all files that have Header file pollution.

For example, (Running program on above example, myProject1):

java code_analysis –i /data/projects/myProject1

Class1.hpp is included twice in Main.cpp. Remove Class1.hpp from one of the files below: 1. Class2.hpp includes Class1.hpp
2. Main.cpp includes Class1.hpp

myProject1/
- Class1.hpp - Class1.cpp - Class2.hpp - Class2.cpp - Main.cpp

Class2.hpp includes Class1.hpp
Main.cpp includes Class1.hpp and Class2.hpp

Explanation / Answer

193 down vote accepted

Historically, the first extensions used for C++ were .c and .h, exactly like for C. This caused practical problems, especially the .c which didn't allow build systems to easily differentiate C++ and C files.

Unix, on which C++ has been developed, has case sensitive file systems. So some used .C for C++ files. Other used .c++, .cc and .cxx. .C and .c++ have the problem that they aren't available on other file systems and their use quickly dropped. DOS and Windows C++ compilers tended to use .cpp, and some of them make the choice difficult, if not impossible, to configure. Portability consideration made that choice the most common, even outside MS-Windows.

Headers have used the corresponding .H, .h++, .hh, .hxx and .hpp. But unlike the main files, .h remains to this day a popular choice for C++ even with the disadvantage that it doesn't allow to know if the header can be included in C context or not. Standard headers now have no extension at all.

Additionally, some are using .ii, .ixx, .ipp, .inl for headers providing inline definitions and .txx, .tpp and .tpl for template definitions. Those are either included in the headers providing the definition, or manually in the contexts where they are needed.

Compilers and tools usually don't care about what extensions are used, but using an extension that they associate with C++ prevents the need to track out how to configure them so they correctly recognize the language used.

2017 edit: the experimental module support of Visual Studio recognize .ixx as a default extension for module interfaces, clang++ is recognizing .c++m, .cppm and .cxxm for the same purpose.

Historically, the first extensions used for C++ were .c and .h, exactly like for C. This caused practical problems, especially the .c which didn't allow build systems to easily differentiate C++ and C files.

Unix, on which C++ has been developed, has case sensitive file systems. So some used .C for C++ files. Other used .c++, .cc and .cxx. .C and .c++ have the problem that they aren't available on other file systems and their use quickly dropped. DOS and Windows C++ compilers tended to use .cpp, and some of them make the choice difficult, if not impossible, to configure. Portability consideration made that choice the most common, even outside MS-Windows.

Headers have used the corresponding .H, .h++, .hh, .hxx and .hpp. But unlike the main files, .h remains to this day a popular choice for C++ even with the disadvantage that it doesn't allow to know if the header can be included in C context or not. Standard headers now have no extension at all.

Additionally, some are using .ii, .ixx, .ipp, .inl for headers providing inline definitions and .txx, .tpp and .tpl for template definitions. Those are either included in the headers providing the definition, or manually in the contexts where they are needed.

Compilers and tools usually don't care about what extensions are used, but using an extension that they associate with C++ prevents the need to track out how to configure them so they correctly recognize the language used.

2017 edit: the experimental module support of Visual Studio recognize .ixx as a default extension for module interfaces, clang++ is recognizing .c++m, .cppm and .cxxm for the same purpose.