user3791401
user3791401

Reputation: 17

"something not a structure or union"

So i keep geting an error

 request for member ‘iArray’ in something not a structure or union
 int place = q.iArray[q.in];//reorder

I have another function and this call works perfect but for some reason in my consumer fucntion it producers this call...

my cdoe is:

   typedef struct _struct_x
{
  int iArray[MAX_COUNT];
  int in;
  int out;

} struct_x;

struct_x q;

void * consumer (void *t)
{
  int tid = * (int *)t;
  printf ("consumer started\n");
   while (!done)
    {
        printf("IM IN THIS LOOP\n");
        int q = rand() % 1000 + 1;  
        pthread_mutex_lock (&count_mutex);
        usleep(q*1000);
            if (count <= 0)
            {
            //its empty..
            }
            else{

                int place = q.iArray[q.in];//reorder
                q.in = (q.in+1)%MAX_COUNT;
                int facto = 0;
                printf("Consumer removed %d, computed %d != &d, queue size = %d\n",place,place,facto,count);
                count--;

            }   

        pthread_mutex_unlock (&count_mutex);

    }
  printf ("T2[%d] thread done.\n", tid);
  pthread_exit (NULL);
}

I guess my main question is what causes such an error

Upvotes: 0

Views: 104

Answers (1)

sray
sray

Reputation: 584

You have redefined q as an integer in this line -

int q = rand() % 1000 + 1; 

That is causing the compilation error.

Upvotes: 2

Related Questions