G local variables heap dynamically allocated storage

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: now value of N at compile ?me ¢༊  Variable dimensions, explicit indexing —༉  Tradi?onal way to implement dynamic arrays ¢༊  Variable dimensions, implicit indexing —༉  Now supported by gcc #define N 16 typedef int fix_matrix[N][N]; /* Get element a[i][j] */ int fix_ele (fix_matrix a, int i, int j) { return a[i][j]; } #define IDX(n, i, j) ((i)*(n)+(j)) /* Get element a[i][j] */ int vec_ele (int n, int *a, int i, int j) { return a[IDX(n,i,j)]; } /* Get element a[i][j] */ int var_ele (int n, int a[n][n], int i, int j) { return a[i][j]; } 18 16 X 16 MATRIX ACCESS ¢༊  Array Elements §༊  Address A + i * (C * K) + j * K §༊  C = 16, K = 4 /* Get element a[i][j] */ int fix_ele(fix_matrix a, int i, int j) { return a[i][j]; } movl sall movl sall addl movl 12(%ebp), %edx $6, %edx 16(%ebp), %eax $2, %eax 8(%ebp), %eax (%eax,%edx), %eax # # # # # # i i*64 j j*4 a + j*4 *(a + j*4 + i*64) 19 N X N MATRIX ACCESS ¢༊  Array...
View Full Document

Ask a homework question - tutors are online