Publications Details

Publications / Conference

Proposal for a numerical array library

One of the most widely recognized inadequacies of C is its low-level treatment of arrays. Arrays are not first-class objects in C; an array name in an expression almost always decays into a pointer to the underlying type. This is unfortunate, especially since an increasing number of high-performance computers are optimized for calculations involving arrays of numbers. On such machines, double[] may be regarded as an intrinsic data type comparable to double or int and quite distinct from double. This weakness of C is acknowledged in the ARM, where it is suggested that the inadequacies of the C array can be overcome in C++ by wrapping it in a class that supplies dynamic memory management bounds checking, operator syntax, and other useful features. Such ``smart arrays`` can in fact supply the same functionality as the first-class arrays found in other high-level, general-purpose programming languages. Unfortunately, they are typically expensive in both time and memory and make poor use of advanced floating-point architectures. The reasons for these difficulties are discussed in X3JI6/92-0076//WG21/N0153, ``Optimization of Expressions Involving Array Classes.`` Is there a better solution? The most obvious solution is to make arrays first-class objects and add the functionality mentioned in the previous paragraph. However, this would destroy C compatibility and significantly alter the C++ language. Major conflicts with existing practice would seem inevitable. I propose instead that a numerical array class be adopted as part of the C++ standard library. This class will have the functionality appropriate for the intrinsic arrays found on most high-performance computers, and the compilers written for these computers will be free to implement it as a built-in class. On other platforms, this class may be defined normally, and will provide users with basic array functionality without imposing an excessive burden on the implementor.