C Structure Pointer Problem

Posted by Halo on Stack Overflow See other posts from Stack Overflow or by Halo
Published on 2010-04-03T14:17:54Z Indexed on 2010/04/03 14:23 UTC
Read the original article Hit count: 212

Filed under:
|
|

I have this struct;

#define BUFSIZE 10
struct shared_data {
    pthread_mutex_t th_mutex_queue;
    int count;

    int data_buffer_allocation[BUFSIZE];
    int data_buffers[BUFSIZE][100];
};

and I want to allocate one of the data_buffers for a process, for that purpose I execute the following function;

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;
}

but the compiler warns me that I'm comparing pointer to a value. When I put a & in front of sdata_ptr it calms down but I'm not sure if it will work. Isn't what I wrote above supposed to be true?

© Stack Overflow or respective owner

Related posts about c

    Related posts about struct