由于我对将类型内存分配给指针的理解薄弱,以下导致调用 barrier_create 时出现总线错误(从未打印过“hi”)。
typedef struct barrier barrier_t;
typedef struct barrier *barrier_p;
barrier_p test_barrier_p;
int main(int argc, char *argv[]) {
barrier_create(*test_barrier_p);
}
int barrier_create(barrier_p *barrier_pointer) {
printf("hi\n");
barrier_p old_barrier, new_barrier;
int count;
old_barrier = (barrier_p) *barrier_pointer;
new_barrier = (barrier_p) malloc(sizeof(*new_barrier));
count = pthread_mutex_init(&new_barrier->lock, NULL);
new_barrier->is_valid = VALID_BARRIER;
new_barrier->counter = 0;
new_barrier->release_flag = 0;
*barrier_pointer = new_barrier;
return HAPPY_HAPPY_JOY_JOY;
}
我错过了什么或输入错误?