求问段错误出现的可能性
程序代码:
double * dt_n_pc_x[NUM_CELL]; initialize_memory(dt_n_pc_x,NUM_CELL,CELL_POINT); double * dt_n_pc_y[NUM_CELL]; initialize_memory(dt_n_pc_y,NUM_CELL,CELL_POINT); double * posi_l_pc[NUM_CELL]; initialize_memory(posi_l_pc,NUM_CELL,CELL_POINT); printf("duan1\n"); double * posi_n_pc_x[NUM_CELL]; printf("duan2\n"); initialize_memory(posi_n_pc_x,NUM_CELL,CELL_POINT); printf("duan3\n"); double * posi_n_pc_y[NUM_CELL]; printf("duan4\n"); initialize_memory(posi_n_pc_y,NUM_CELL,CELL_POINT); printf("duan5\n"); double * dt_posi_l_n_pc_x[NUM_CELL]; initialize_memory(dt_posi_l_n_pc_x,NUM_CELL,CELL_POINT); double * dt_posi_l_n_pc_y[NUM_CELL]; initialize_memory(dt_posi_l_n_pc_y,NUM_CELL,CELL_POINT);
程序代码:
void initialize_memory(double * p[],int N,int * CELL_POINT[]) { int k,i; for(k = 0; k < N; ++k) { p[k] = (double *)malloc(CELL_POINT[k][0] * sizeof(double)); if(p[k] == NULL) { for(i = 0; i < k; ++i) { free(p[i]); p[i] = NULL; } printf("Initialize_memory fail.\n"); exit(5); } } }
求问大虾们为什么当NUM_CELL变大后,程序在断点3到4之间(也就是double * posi_n_pc_y[NUM_CELL];这句)会出现段错误。
(编译环境ubuntu14 gcc)