The following procedure with some expressions omitted

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: _opt that uses optimizations similar to those in the assembly code, in the same style as the code in Figure 3.23(b). 3.8.6 Dynamically Allocated Arrays C only supports multidimensional arrays where the sizes (with the possible exception of the first dimension) are known at compile time. In many applications, we require code that will work for arbitrary size arrays that have been dynamically allocated. For these we must explicitly encode the mapping of multidimensional arrays into one-dimensional ones. We can define a data type var_matrix as simply an int *: typedef int *var_matrix; To allocate and initialize storage for an Ò ¢ Ò array of integers, we use the Unix library function calloc: 3.8. ARRAY ALLOCATION AND ACCESS 1 2 3 4 151 var_matrix new_var_matrix(int n) { return (var_matrix) calloc(sizeof(int), n * n); } The calloc function (documented as part of ANSI C [30, 37]) takes two arguments: the size of each array element and the number of array elements required. It attempts to allocate space for the entire array. If successful, it initializes the entire region of memory to 0s and returns a pointer to the first byte. If insuffici...
View Full Document

This note was uploaded on 09/02/2010 for the course ELECTRICAL 360 taught by Professor Schultz during the Spring '10 term at BYU.

Ask a homework question - tutors are online