Criticism of the C programming language: Difference between revisions

Content deleted Content added
Arrays: Fortran 90, for example, passes bounds with the array (as long as you have an explicit interface), like a C++ array class.
Line 29:
Although C supports static arrays, it is not required that array indexes be validated ([[bounds checking]]). For example, one can write to the sixth element of an array with five elements, yielding generally undesirable results. This type of bug, called a ''[[buffer overflow]],'' has been notorious as the source of a number of security problems. On the other hand, since [[bounds checking elimination]] technology was largely nonexistent when C was defined, bounds checking came with a severe performance penalty, particularly in numerical computation. By comparison, a few years earlier some [[Fortran]] compilers had a switch to toggle bounds checking on or off; however, this would have been much less useful for C, where array arguments are passed as simple pointers.
 
Multidimensional arrays are commonly used in numerical algorithms (mainly from applied [[linear algebra]]) to store matrices. The structure of the C array is particularly well suited to this particular task, provided one remembers to count indices starting from 0 instead of 1. However, since arrays are passed merely as pointers, the bounds of the array must be explicitly passed to any subroutine that requires them, and dynamically allocated, multidimensional arrays cannot be addressed in the natural way. These issues isare discussed in the book ''[[Numerical Recipes|Numerical Recipes in C]]'', chapter 1.2, page 20''ff'' ([http://www.library.cornell.edu/nr/bookcpdf/c1-2.pdf read online]). InTheir thatsolution bookto therethe isaddressing problem requires the redifinition of multidimensional arrays as an array of pointers to one-dimensional arrays. That book also aprovides solution based on negative indexing which introduces other dangers. Starting indices at 0 has been assimilated into the computing culture, and is no longer as alien a notion as it seemed when C was first introduced.
 
==Variadic functions==