We consider the problem of converting C pointers to the less flexible concept of references. Our main application is converting scientific applications from C to Java. We provide a general method to model essentially all features of pointers using references. The model is easily implemented in Java. We give optimizations that map key facilities like arrays and structures onto the obvious Java equivalents, arrays and objects. These improvements make the conversion "optimal" for all typed pointers. For untyped pointers, we can still fall back on the general model, hence providing general automatic conversion from C to Java code, whose efficiency improves with the quality of the C code.
The C language is well known for its overly flexible pointers. A pointer may represent the address of an individual value, an array, a structure, or a position in an array or structure. Pointers can be cast into other pointer types or integers, split into pieces and later rejoined, and can take part in arithmetic operations. While this gives the programmer immense flexibility, most of these abilities are considered unnecessary, and when used are dangerous and lead to code that is difficult to debug. For this reason, many modern languages such as Java support a much more restricted model called references. The programmer has limited access to the references themselves; typically, one can only assign to a reference and test whether two references point to the same object. Other uses of a reference are implicitly about the object it refers to; usually, the programmer does not explicitly dereference or take the address of an object. This leads to significantly safer and simpler code.
Since C is popular, there is a lot of code written in it. Many want to extend such programs and exploit features of more modern programming languages. For example, one may want to port an application to Java for demonstration on the World Wide Web. Since C and Java are similar in syntax, the main difficulty in converting between the two is the conversion between major concepts, in particular pointers and references.Our main focus is on translating scientific applications written in C. A significant example of such a program is SuperLU, a state-of-the-art general sparse linear solver that is available only in C.
The possible methods for passing basic values such as integers to functions by reference in Java. We know of one system supporting this, EPP. EPP is a framework for Java preprocessors and one example, called ref, adds an operator "&" for passing values by reference. It implements this using one element arrays, but in such a way that does not allow taking general addresses of basic values.
View the original article here
No comments:
Post a Comment