Variable-size arrays in C
Both the original C language and ANSI C handle vectors of indefinite length, but neither caters for multidimensional arrays whose bounds are determined during execution. Such a facility is especially useful for numerical library routines, but is currently painful to program. Many of the issues, and...
Main Author: | |
---|---|
Other Authors: | |
Format: | Text |
Language: | English |
Published: |
1990
|
Subjects: | |
Online Access: | http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1087.8790 |
id |
ftciteseerx:oai:CiteSeerX.psu:10.1.1.1087.8790 |
---|---|
record_format |
openpolar |
spelling |
ftciteseerx:oai:CiteSeerX.psu:10.1.1.1087.8790 2023-05-15T18:32:45+02:00 Variable-size arrays in C Dennis M Ritchie The Pennsylvania State University CiteSeerX Archives 1990 application/pdf http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1087.8790 en eng http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1087.8790 Metadata may be used without restrictions as long as the oai identifier remains attached to it. https://www.bell-labs.com/usr/dmr/www/vararray.pdf text 1990 ftciteseerx 2020-05-24T00:17:30Z Both the original C language and ANSI C handle vectors of indefinite length, but neither caters for multidimensional arrays whose bounds are determined during execution. Such a facility is especially useful for numerical library routines, but is currently painful to program. Many of the issues, and some suggested language changes, were discussed by Tom MacDonald in J. C Language Translation 1:3 (December, 1989, pp. 215-233). Some compilers, for example the GCC compiler from the Free Software Foundation, already have extensions in this area. This note discusses problems in these approaches, and offers a differing proposal for an extension. Previous thoughts (including my own) have fixed on the idea of allowing general expressions, and not merely constants, as bounds for automatic arrays. Although this extension, with careful restrictions, seems to fit into the structure of the existing language, and is useful by itself, it presents implementation difficulties in some run-time systems. Moreover, I argue that this proposal alone does not properly resolve the question of function parameters that involve varying arrays. The rules for both the GCC and MacDonald schemes are difficult to use and comprehend, and are difficult to formalize even to the level of the current ANSI standard; in particular, the type calculus for variable-sized arrays is murky for both. In the existing ANSI C language, the type and value of an object p suffice to determine the evaluation of operations on it. In particular, if p is a pointer, the code generated for expressions like p[i] and p[i][j] depend only on its type, because any necessary array bounds are part of the type of p. In the MacDonald and GCC extensions, the values of non-constant array bounds are not tied firmly to its type. My proposal, by contrast, is to avoid allowing variable-sized arrays as declared objects, but to provide pointers to such arrays; the pointers carry the array bounds inside themselves. This will preserve the property that pointer arithmetic and dereferencing ... Text The Pointers Unknown |
institution |
Open Polar |
collection |
Unknown |
op_collection_id |
ftciteseerx |
language |
English |
description |
Both the original C language and ANSI C handle vectors of indefinite length, but neither caters for multidimensional arrays whose bounds are determined during execution. Such a facility is especially useful for numerical library routines, but is currently painful to program. Many of the issues, and some suggested language changes, were discussed by Tom MacDonald in J. C Language Translation 1:3 (December, 1989, pp. 215-233). Some compilers, for example the GCC compiler from the Free Software Foundation, already have extensions in this area. This note discusses problems in these approaches, and offers a differing proposal for an extension. Previous thoughts (including my own) have fixed on the idea of allowing general expressions, and not merely constants, as bounds for automatic arrays. Although this extension, with careful restrictions, seems to fit into the structure of the existing language, and is useful by itself, it presents implementation difficulties in some run-time systems. Moreover, I argue that this proposal alone does not properly resolve the question of function parameters that involve varying arrays. The rules for both the GCC and MacDonald schemes are difficult to use and comprehend, and are difficult to formalize even to the level of the current ANSI standard; in particular, the type calculus for variable-sized arrays is murky for both. In the existing ANSI C language, the type and value of an object p suffice to determine the evaluation of operations on it. In particular, if p is a pointer, the code generated for expressions like p[i] and p[i][j] depend only on its type, because any necessary array bounds are part of the type of p. In the MacDonald and GCC extensions, the values of non-constant array bounds are not tied firmly to its type. My proposal, by contrast, is to avoid allowing variable-sized arrays as declared objects, but to provide pointers to such arrays; the pointers carry the array bounds inside themselves. This will preserve the property that pointer arithmetic and dereferencing ... |
author2 |
The Pennsylvania State University CiteSeerX Archives |
format |
Text |
author |
Dennis M Ritchie |
spellingShingle |
Dennis M Ritchie Variable-size arrays in C |
author_facet |
Dennis M Ritchie |
author_sort |
Dennis M Ritchie |
title |
Variable-size arrays in C |
title_short |
Variable-size arrays in C |
title_full |
Variable-size arrays in C |
title_fullStr |
Variable-size arrays in C |
title_full_unstemmed |
Variable-size arrays in C |
title_sort |
variable-size arrays in c |
publishDate |
1990 |
url |
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1087.8790 |
genre |
The Pointers |
genre_facet |
The Pointers |
op_source |
https://www.bell-labs.com/usr/dmr/www/vararray.pdf |
op_relation |
http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.1087.8790 |
op_rights |
Metadata may be used without restrictions as long as the oai identifier remains attached to it. |
_version_ |
1766216923552415744 |