我有这个结构;C结构指针问题
#define BUFSIZE 10
struct shared_data {
pthread_mutex_t th_mutex_queue;
int count;
int data_buffer_allocation[BUFSIZE];
int data_buffers[BUFSIZE][100];
};
我想为进程分配一个data_buffers,为此我执行下面的函数;
int allocate_data_buffer(int pid) {
int i;
for (i = 0; i < BUFSIZE; i++) {
if (sdata_ptr->data_buffer_allocation[i] == NULL) {
sdata_ptr->data_buffer_allocation[i] = pid;
return i;
}
}
return -1;
}
但编译器警告我,我正在比较指向值的指针。当我在sdata_ptr前面放置一个&
时,它平静下来,但我不确定它是否会起作用。是不是我上面写的应该是真的?
为了达到预期效果(在NULL修复之后),请记住,您需要初始化这些值。 – KevenK 2010-04-03 14:31:17