apr-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Damir Dezeljin <program...@nib.si>
Subject apr_queue.c: a question (I don't realy understand this)
Date Fri, 08 Nov 2002 10:30:49 GMT
Hi.

I looked in the 'testqueue.c' sample from apr-util package (I checked out
it yesterday from the CVS). There is defined a function
  consumer(apr_thread_t *thd, void *data)
which is used to get elements from the queue. *data is then casted to:
  apr_queue_t *q = (apr_queue_t*)data;
Then on line 114 it is called
  val = **(int**)v;
val is of type int (int val;). Then on the next line it is printed with
printf();

I realy don't understand this why I need to do **(int**) (four star hotel
;) ).

So I looked in the sources where apr_queue is implemented and I found:
  struct apr_queue_t {
      void              **data;
      ...
  }

Then in:
  apr_queue_create(apr_queue_t **q, int queue_capacity, apr_pool_t *a)
an array of pointers to void * is alocated (apr_queue.c:169). So ...
  queue->data[] is an array of pointers to void *

In function:
  apr_queue_push(apr_queue_t *queue, void *data)
data is added to the queue on line 231:
  queue->data[queue->in] = data;

Function:
  apr_queue_pop(apr_queue_t *queue, void **data)
get data from the queue on the line 345:
  *data = &queue->data[queue->out];

This is why **(int **) is needed in the test program. But why
queue->data[] is dereferenced (so why there is &)???

And what happend with the test program on a 64bit machine (I don't have
such a machine to test, but I think that pointers on such machines are 64
bit so that the cast **(int **) will do something wrong - I'm not shure on
this).


Regards,
Dezo


Mime
View raw message