Cjj: a subset of C++ compliant with Java


The C++ programming language offers a wide range of coding alternatives to programmers. Some language characteristics inherited from C are potential sources of problems during the evolution of a system. Global variables, arbitrary branches, pointers, memory management instructions and macro directives are examples of them. The resulting code may be difficult to understand, maintain and test, if such language features are used without proper discipline.

The Java language was designed with the explicit goal of excluding all troublesome features that can be found in C++, by disregarding some of them (e.g., globals), and disciplining other ones (e.g., pointers). For several companies the migration to Java is not strategically feasible. Nevertheless, the adoption of its philosophy within C++ code could help improve the quality of the software. In this paper a subset of C++, named Cjj, is defined which is compliant with Java, in that it enforces a Java-like programming style, while forbidding all C++ constructs that are in contrast with it. A tool for the verification of the compliance of an input source with Cjj was developed. It verifies if any of the constraints defining Cjj is violated.