C pointer frustration EXC_BAD_ACCESS -


can please tell me what's wrong following code? i'm getting exc_bad_access, not access memory. reason: kern_invalid_address

i declare global array of 7 pointers, each points int array, of different sizes.

int **pt_all_arrays[7]; 

in function a()

    (int = 0; < 7; ++i) {         int array_size = function_that_returns_array_size();         int *myarray = (int *)malloc(array_size * sizeof (int));          // work...              // store array in big array         *(pt_all_arrays[i]) = myarray;  <-----exception     } 

the exception thrown on last line. i'm running on mac, gcc -std=gnu99

you want declare

int *pt_all_arrays[7]; 

and assign as

pt_all_arrays[i] = myarray; 

with int **pt_all_arrays[7]; create array of pointer pointer int, not want.

and *(pt_all_arrays[i]) = myarray; trying change address of array not valid.

example

int array[7]; int *pi; array = pi; //this not valid. 

Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

asp.net - Razor Page Hosted on IIS 6 Fails Every Morning -

c++ - wxwidget compiling on windows command prompt -